Friday, September 10, 2010

The referenced assembly "log4net" could not be resolved because it has a dependency on System.Web

Here is a riddle, what is wrong with this brand new .NET 4.0 console application that only references the log4net 1.2.10.0 dll?

error CS0246: The type or namespace name 'log4net' could not be found (are you missing a using directive or an assembly reference?)
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3253: 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.

Answer

The projects target framework is set to the client profile version of the .NET framework, which excludes (typically) server side assemblies such as System.Web.

Changing the Target framework under the Application project properties resolves the issue.

See Also: