Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

namespaces

c#

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.

like image 414
RanRag Avatar asked Aug 07 '12 21:08

RanRag


People also ask

How do you fix the type or namespace name could not be found?

The solution in this case is to either upgrade the framework target of the application (Project A), or downgrade the target of referenced assembly (Project B).

How do I fix cs0234?

To fix this error, simply update the example . csproj file to use a previous System. CommandLine version. Note that this package is only used to parse the options for the example.


2 Answers

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).

like image 173
Actek14 Avatar answered Sep 28 '22 07:09

Actek14


  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

like image 37
Vishwa G Avatar answered Sep 28 '22 06:09

Vishwa G