Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error thrown when I'm trying to load log4net assembly

Tags:

log4net

I'm try to build project that use LinqToExcel library. Additionally, I'm use log4net to write logs.

My problem started when I'm tryomg to run this lines of code:

var excel = new ExcelQueryFactory(ExcelPath);
return (from r in excel.Worksheet<RowDetails>(company.Name)
        select r).Count();

This line thrown exception:

ERROR MyProj.Program Main:System.IO.FileLoadException: Could not load file or assembly 'log4net, Version=1.2.11.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) File name: 'log4net, Version=1.2.11.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a'

It's important to note that I'm successful to use log4net before this line.

I would appreciate any help.

Thanks a lots!

like image 892
omer Avatar asked Apr 29 '12 14:04

omer


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.


2 Answers

As marc_s pointed out, this problem usually appears when trying to load different versions of the same assembly. Make sure, that your project uses the same assembly version as the LinqToExcel library, which is also dependent on log4net. Also any other libraries should use the same assembly version. To solve the issue, you can also try to use assembly redirect in your app.config like so:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" culture="neutral" />
        <bindingRedirect oldVersion="1.2.10.0" newVersion="1.2.11.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
like image 56
Tomas Chlouba Avatar answered Oct 30 '22 14:10

Tomas Chlouba


try to install it using nuget

Install-Package log4net -Version 2.0.0

Version 2.0.0 is for log4net 1.2.11

like image 6
Sagi Avatar answered Oct 30 '22 15:10

Sagi