Namespace not found!

I created a solution called Foo . A class library called Foo.Common added. A console application has Foo.Common added to call library code from ConsoleApp called.

I referenced Foo.Common from ConsoleApp and typed:

 using Foo.Common; public class Program { CommonClass c = new CommonClass(); static void Main(string[] args) { } } 

and return this:

Error 1 The type or namespace name '**Foo**' could not be found (are you missing a using directive or an assembly reference?) Z:\Foo\Solution1\ConsoleApplication1\Program.cs 3 11 ConsoleApplication1

Why am I getting this?

what's happening?

+6
source share
6 answers

Make sure that

  • The ConsoleApp project has a link to the Foo.Common project (do not view Foo.Common.dll),

    Screen shot

  • the file contains the using directive for the namespace in which the CommonClass declared, and

  • CommonClass declared as public .

So your files should look like this:


CommonClass.cs in a Foo.Common project:

 namespace Foo.Common { public class CommonClass { public CommonClass() { } } } 

Program.cs in the ConsoleApp project:

 using Foo.Common; namespace ConsoleApp { public class Program { public static void Main() { CommonClass x = new CommonClass(); } } } 
+6
source

Make sure that in your project settings, the target structure is specified as the .NET Framework 4, and not the .NET Framework 4 Client Profile. I got the same behavior when it was configured on the client profile, and these were the fixes as soon as I installed it only in the regular .NET Framework 4.

+2
source

Right click on the new console / project solution and add the link and add the project containing the Foo namespace

0
source

Have you added a link to the library? Take a look at the Links section of the console project. If it is not there, you need to add it.

0
source

I posted this as a comment, but I want to expand it here. This is likely due to the use as a statement, not a keyword. It seems you have something like the following:

 using System; namespace TestNamespace { using Foo.Common; public Class { } } 

Try

 using System; using Foo.Common; namespace TestNamespace { public Class { } } 

Instead.

0
source

It looks like Foo Bar got this error because its target project structure was configured on the client profile.

I just thought that I would add another β€œsolution” - I created a library focused on the 4.5 framework. My old project broke 4 frames. I got this error.

Changing the old project to 4.5 made it work.

0
source

Source: https://habr.com/ru/post/892806/


All Articles