Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4net reference assembly dependency issue [duplicate]

Tags:

c#

.net

log4net

I am a Java developer and have just started learning C# to develop a couple project. I am happy to see that many Java frameworks that I am used to work with (log4j, ant, hibernate etc.) have their .net versions (log4net, nant, nhibernate).

I have just created a project and tried to put log4net assembly reference in it, but I am having the following warning (followed by 4 errors informing failure to recognize log4net namespace and classes):

The referenced assembly "log4net" could not be resolved because it has a dependency on "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which is not in the currently targeted framework ".NETFramework,Version=v4.0,Profile=Client". Please remove references to assemblies not in the targeted framework or consider retargeting your project.

I added reference to System.Web.ApplicationServices and System.Web.Services but it's not working. Any help on solving this dependency issue will be much appreciated.

Thanks

like image 517
craftsman Avatar asked Dec 23 '10 12:12

craftsman


3 Answers

UPDATE:

If you're still getting this error, you're using an out-of-date version of log4net and you should consider updating to the current version, which does not require the full .NET 4.0 framework. Thanks to @Philippe for pointing this out in a comment.


Your project is referencing the .NET 4.0 client profile which does not include System.Web; you actually need to reference the full framework.

See How To: Target a Specific .NET Framework Version or Profile on MSDN for directions.

  1. In Visual Studio, open the project you want to change.
  2. Right-click the project in Solution Explorer and then click Properties.
  3. In the Project Designer, locate the Target Framework list, as follows.

    • For Visual Basic projects, click the Compile tab and then click Advanced Compile Options. The Target Framework list is in the Advanced Compiler Settings dialog box.
    • For Visual C# projects, the Target Framework list is on the Application tab of the Project Designer. For more information, see Application Page, Project Designer (C#).
    • For Visual F# projects, the Target Framework list is on the Application tab of the Project Designer.
  4. In the Target Framework list, select the .NET Framework version or profile that you want. When you click OK, the project unloads and then reloads in the integrated development environment (IDE). The project now targets the .NET Framework version that you just selected.

Possibly also of interest is Troubleshooting .NET Framework Targeting Errors.

like image 79
Mark Rushakoff Avatar answered Oct 06 '22 00:10

Mark Rushakoff


Set your project to target the ".Net 4.0 Framework", not the ".Net 4.0 Framework Client Profile" in the project properties dialog.

like image 20
Lloyd Avatar answered Oct 05 '22 22:10

Lloyd


Just small update. This issue has been logged almost 3 years ago and was fixed just this month. So next version of log4net (after 1.2.10) should be fine to work with client profile frameworks.

https://issues.apache.org/jira/browse/LOG4NET-174

like image 33
Maciej Avatar answered Oct 05 '22 22:10

Maciej