我正在尝试构建使用 LinqToExcel 库的项目。另外,我使用 log4net 来写入日志。
当我尝试运行这行代码时,我的问题开始了:
var excel = new ExcelQueryFactory(ExcelPath);
return (from r in excel.Worksheet<RowDetails>(company.Name)
select r).Count();
该行抛出异常:
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'
值得注意的是,我在这行之前成功使用了 log4net。
如果有任何帮助,我将不胜感激。
非常感谢!
最佳答案
正如 marc_s 指出的那样,当尝试加载同一程序集的不同版本时,通常会出现此问题。确保您的项目使用与 LinqToExcel 库相同的程序集版本,该库也依赖于 log4net。此外,任何其他库都应该使用相同的程序集版本。要解决此问题,您还可以尝试在 app.config 中使用程序集重定向,如下所示:
<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>
关于log4net - 当我尝试加载 log4net 程序集时抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10373009/