You cannot reference other projects

I want to create 3 projects in a Visual Studio solution:

  • Windows Service (Business Layer, Common Layer, log4net.dll links)
  • Business Layer (Common Layer links, log4net.dll)
  • General level (log4net.dll links)

Steps:

  • I am creating a Business Layer and Common layer using the wizard without any changes. I set the links and everything works.

  • Then I create a new Windows Service project for the solution. I notice that instead of Any CPU, the target x86 platform is being added. I refer to 3 things, and the code is colored correctly, pre-compilation errors disappear: this means that the links are recognized.

  • When I create the solution, however, the Windows service project has compilation errors: I cannot find any reference assemblies.

What's going on here? Is the x86 configuration calling "Type or namespace name" log4net "cannot be found (are you missing the using directive or assembly references?)" Errors?

I made the Windows service project use any processor configuration. I checked every link twice, they are correct. However, I cannot say anything.

System Specifications:

  • Windows 7 x64 SP1 Visual Studio 2010
  • Final
+4
source share
3 answers

Well, you have already found the answer. Log4net has a dependency on System.Web.dll, an assembly not available in the client profile. The likely main reason for this dependency is the log4net.Appender.AspNetTraceAppender class, it uses the HttpContext class and requires System.Web.

Right now, this is what you need to know from the library documentation, or finding it difficult. The building generates a warning, but this is only a warning, not an error, it is easy to skip:

C: \ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ Microsoft.Common.targets (1360.9): warning MSB3253: assembly reference "C: \ projects \ WindowsFormsApplication2 \ ClassLibrary1 \ bin \ Debug \ ClassLibrary1.dll" cannot be resolved because it has a dependency on "System.Web, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a", which is not in the target environment ".NETFramework, Version = v4.0", Profile = Client ". Remove assembly references not in the target structure or do not consider redirecting your project.

The following are errors from any statements in your code that attempt to reference classes in an assembly containing a link to log4net.

C: \ projects \ WindowsFormsApplication2 \ WindowsFormsApplication2 \ Form1.cs (12,9): error CS0246: the name of the type or namespace 'ClassLibrary1' could not be found (do you miss the using directive or assembly references?)

You will not miss either, and there can be many mistakes if you do not create incrementally when writing code. You focus on errors and don’t understand that warning is a true source of errors. Another nasty trap is that IntelliSense is happy at first, it solves the build problem correctly. There is some evidence that the warning is not always generated, simply because many programmers do not seem to notice it. I have not yet found a scenario where this is the case. Not sure.

+6
source

Having lost a few handfuls of my hair, I found the answer fooobar.com/questions/67459 / ... , which solved the problem. But why will Visual Studio add a Windows service with x86 as the target platform and .Net Framework 4 Client Profile as the target environment?

+3
source

Check if solutions are built. You can do this by right-clicking on a solution> Properties> Configuration Properties. Make sure all solutions are built.

0
source

All Articles