asp.net - 无法加载文件或程序集 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821'

标签 asp.net wcf log4net

我已经使用 NuGet 包管理器在我的项目中添加了 Log4Net,它显示我的系统上安装了 2.3 版。
这是我的配置条目:

  <configSections>
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
  </configSections>
然后在此处引用此文件
  <log4net configSource="Log4Net.config" />
  <system.serviceModel>
但是当我运行网站时。显示以下异常。

Could not load file or assembly 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileLoadException: Could not load file or assembly 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


我已经看到 dll 存在于 bin 文件夹中,但显示的是 1.2.13.0 版本。
如何更改程序集版本?

最佳答案

似乎您的解决方案中的一个项目或某些第 3 方 dll 是使用不同版本的 log4net 构建的。您可以在所有项目中更新对 log4net 的引用(使用 3rd 方 dll,这将无济于事),或者您可以将程序集重定向设置添加到 web.config (app.config),这会将 log4net 的指定版本/版本重定向到新版本。

将此部分放在您的 web.config (app.config) 配置元素下的任何位置

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="log4net"
                          publicKeyToken="1b44e1d426115821"
                          culture="neutral" />
            <bindingRedirect oldVersion="1.2.10.0"
                         newVersion="1.2.13.0"/>
        </dependentAssembly>
    </assemblyBinding>
</runtime>

欲了解更多信息,请查看 documentation page on msdn .

关于asp.net - 无法加载文件或程序集 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30611640/

相关文章:

.net - 使用 log4net 以及在何处实现它并与 elmah 一起使用?

log4net - 在运行时多次更改日志文件的名称

c# - 如何使用 Log4Net 实用程序使用 C# 登录数据库

asp.net - Global.asax Application_Error 是异步的吗?

c# - 从 WCF 服务引发 FaultException<T> 导致 'The creator of this fault did not specify a Reason.'

javascript - 浏览器不支持我在 asp.net 中的字体

wcf - 用于测试 WCF Rest 服务的测试客户端还是仅使用浏览器?

c# - WCF REST - "Get"使用复杂类型

c# - 保护网络服务的最佳方式是什么?

asp.net - 使用 ARR 的 IIS 反向代理存在目录级别问题