Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not load file or assembly log4net

I have added log4net to my project and it is working just fine on my machine, but when I sent the release version of my application to my colleague, he receives this FileNotFoundException:

Could not load file or assembly 'log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a'

But the strange thing is that in my app.config I'm not even using the above version of log4net:

<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="BizWizard.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
</sectionGroup>
like image 596
disasterkid Avatar asked Oct 27 '14 09:10

disasterkid


People also ask

Could not load file or assembly log4net or one of its dependencies?

Solution 1 Just remove it from the dll from your project and then try to build the project. Since you don't need that one. In case you want to include that dll, you should check that, the application pool you are using is compatible with the assembly.

Can not load file or assembly?

In summary if you get the "Could not load file or assembly error", this means that either your projects or their references were built with a reference to a specific version of an assembly which is missing from your bin directory or GAC.

How do I get log4net DLL?

You can download the desired Log4net. dll from this path: http://logging.apache.org/log4net/download.html, Whilst I've also attached the required Log4net.


2 Answers

Do you use other third party libraries? Maybe one of them requires this particular version of log4net. If this is the case, this can be resolved using assembly binding in your applications app.config file.

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" />
      <codeBase version="1.2.13.0" href="log4netv1.2.13.0\log4net.dll" />
    </dependentAssembly>
  </assemblyBinding>
</runtime>

and the put this the 1.2.13.0 version of log4net in a sub-folder called log4netv1.2.13.0

You may also try to redirecting all references to log4net to a specific (your) version using bindingRedirect. http://msdn.microsoft.com/en-us/library/7wd6ex19(v=vs.110).aspx

like image 130
Jan Petter Jetmundsen Avatar answered Sep 19 '22 08:09

Jan Petter Jetmundsen


Ran into the same problem. LinqToExcel library was using different version of log4net.

To solve it:

  • Delete the old log4net version in References.

  • Go to Tools, Nuget Packet Manager, Package Manager Console.

  • Run:

Install-Package log4net -Version 2.0.3

More details here:

https://www.nuget.org/packages/log4net/2.0.3

like image 30
live-love Avatar answered Sep 22 '22 08:09

live-love