Could not load file or assembly log4net

30,913

Solution 1

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

Solution 2

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

Share:
30,913
disasterkid
Author by

disasterkid

Updated on July 27, 2022

Comments

  • disasterkid
    disasterkid almost 2 years

    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>
    
    • csprabala
      csprabala over 9 years
      Look at stackoverflow.com/questions/8743992/… May be this is what is needed in your case.
    • disasterkid
      disasterkid over 9 years
      @csprabala I am trying to do the fixes. But why is it working fine on my machine?
    • Bernd Linde
      Bernd Linde over 9 years
      I know this sounds stupid, but did you send the log4net DLL's with your application to your colleague?
    • disasterkid
      disasterkid over 9 years
      @BerndLinde yes both log4net.dll and log4net.xml are included in the folder.
    • Bernd Linde
      Bernd Linde over 9 years
      Are both systems 64bit? (Reference here)
    • Jan Petter Jetmundsen
      Jan Petter Jetmundsen over 9 years
      Do your colleague use "global assembly cache"? Are some of your dll's being loaded from somewhere else on his computer?
    • disasterkid
      disasterkid over 9 years
      @JanPetterJetmundsen log4net is the only dll we are using in this program.
    • RBT
      RBT almost 3 years
  • disasterkid
    disasterkid over 9 years
    I just downgraded to log4net 1.2.0 and it started working. Since I am not looking for problems in the future I think I'm gonna stick to this for now.
  • Artem A
    Artem A about 7 years
    put some folder, redirect... what are you talking about? All use nuget packages for years! they you can't simply put library in a folder you want and hack the problem!
  • Jessica
    Jessica over 4 years
    The problem with this is, when something else has a dependency on the new version :(