July 1027

log4net Gotcha with .Net 4.0 Applications

I’ve been using log4net in an application for a little while, it took some time to get it set up (maybe I’ll do a post about that in the future?) – but once it was set up I could call it from any form in my project and log whatever I wanted. For this particular project I decided I was going to create a new project and bring in my existing code, upgrade it to .Net 4.0 and fix any build errors. What confused me was that log4net wasn’t recognised in my project.

I checked my references and sure enough log4net showed up in there, my app.config file hadn’t changed but as soon as I tried a Using statement there were problems, trying to compile resulted in the following error: “The type or namespace ‘log4net’ could not be found (are you missing a using directive or an assembly reference?)”. Well quite clearly I wasn’t missing the using statement and I could see log4net in the references.

Well there are 2 versions of .Net 4.0, the Client profile and the full profile; the client profile only has some of the framework, it’s trying to reduce the footprint of the framework – however it doesn’t have system.web.dll and it seems that log4net requires that in order to work. So the solution was to change the Target Framework from “.NET Framework 4 Client Profile” to “.NET Framework 4”, allow Visual Studio to update the project (it will want to close it, which is fine), when it reopens the project log4net will not throw the error and I can get on with converting my project.

Permalink | Comments (1)

Comments

  1. Turkuaz Okul United Kingdom Turkuaz Okul (Sunday, August 15, 2010) #

    I can not use .NET Framework 4.0 yet, because Plesk Do not support it yet. That was a great reading for me. Thanks

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading