Error thrown when I'm trying to load log4net assembly

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!


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>

try to install it using nuget

Install-Package log4net -Version 2.0.0

Version 2.0.0 is for log4net 1.2.11


I'm having similar problem. I think that the problem is in LinqtoExcel referencing Log4Net version 1.2.11, and you have referenced Log4Net sepratly and you get latest 1.2.13 version. In build output you'll end up with 1.2.13, and when LintoExcel calls Log4Net it expects 1.2.11 and error ocures.

链接地址: http://www.djcxy.com/p/43658.html

上一篇: 当项目设置为发布构建时,log4net不起作用

下一篇: 当我尝试加载log4net程序集时抛出错误