[c#] Why am I getting error CS0246: The type or namespace name could not be found?

I am using Snarl C# API to send notifications to snarl.

Now I have saved the content of above url in a file named SnarlNetwork.cs and the content of my test.cs file are:

using SnarlNetworkProtocol;
using System;
class test
{
    public static void Main(String[] args)
    {
        SNP snarl_object = new SNP();
        string hostname = "localhost";
        string hostport = "9887";
        string appName = "Spotify";

        bool val = snarl_object.register(hostname, hostport, appName);

        if (val == true)
        {
            string title = "hello";
            string message = "world";
            string timeout = "5";
            bool newval = snarl_object.notify(hostname, hostport, appName, null, title, message, timeout);

            if (newval == true)
            {
                Console.WriteLine("sucessfull");

            }
        }
    }

}

Now when I try to compile my test.cs file using csc test.cs I get the following error:

C:\Users\Noob\csharp>csc test.cs
Microsoft (R) Visual C# 2008 Compiler version 3.5.30729.4926
for Microsoft (R) .NET Framework version 3.5
Copyright (C) Microsoft Corporation. All rights reserved.

test.cs(1,7): error CS0246: The type or namespace name 'SnarlNetworkProtocol' could not be found (are you missing a using directive or an assembly reference?)

So, what am I doing wrong here because according to me I am not missing any using directive.

This question is related to c# namespaces

The answer is


Check your Web.Config and find namespace = . you can remove or if you need it you must create new


I also got this error due to a missing reference. The reason I did not notice is because Resharper offers to add a using and a reference. Adding the using succeeds (but it's highlighted grey), syntax highlighting of missing classes works (sometimes), but adding the reference fails silently.

When manually adding the reference an error pops up, explaining why adding the reference fails (circular reference). Resharper did not pass this error on to the GUI.


I had the same error when used cs file was located inside project folder, but did not referenced from .csproj of parent project. Intellisence see this file inside project folder, but compiler does not see it because of missing reference in .csproj


I resolved this by making sure my project shared the same .Net Framework version as the projects/libraries it depended on.

It turned out the libraries (projects within the solution) used .Net 4.6.1 and my project was using 4.5.2


I had the same issue when I clone my project from Git and directly build the solution first time. Instead of that go to the local repository in file explorer and double click the solution file (.sln) solved my issue.


  1. On the Solution Explorer tab right click and select Properties

  2. Resolve this issue by updating the Target Framework in the project application settings.

For instance, In my case the project was compiling with .net framework version 4.5.1 but the dll which were referenced were compiled with the version 4.6.1. So have updated the my project version. I hope it works for you.

enter image description here


i also faced same problem,

Reason: why i faced this error is, rather then creating new partial view, i have created class and then renamed its extension from ".cs" to ".cshtml".

Solution: Just delete that rename view and re-create proper partial/full view. it will work fine after that.


This usually happens to me when I have a using statement but have forgotten to reference the assembly that defines the namespace.

But in your case, as the namespace is defined in a file in your project, you have forgotten to tell the compiler about the snarlnetwork.cs file.

See csc compiler examples


I had this error on a MVC Project. And after a long research i found out that the .cs file containing some of the classes i referenced in the main project had a Build Actions set to "Content" ...

After changing it "Content"->"Compile" the error disappeared.


most of the problems cause by .NET Framework. So just go to project properties and change .Net version same as your reference dll.

Done!!!

Hope it's help :)


It might be due to "client profile" of the .NET Framework. Try to use the "full version" of .NET.


Edit: Oh ignore me, you're not using Visual Studio.

Have you added the reference to your project?

As in this sort of thing:

enter image description here


I was using .NET Framework 4.5 but my new library had .NET Framework 4.5.2 and I got the same issue when I tried to build. I solved it by updating my project from 4.5 to 4.5.2 (same as my library).


I had a similar problem after first pulling and starting a new solution. It was fixed in visual studio by first cleaning the project. Then restoring the packages. When I built again, there were no more type or namespace errors.


I have resolved this problem by adding the reference to System.Web.