无法加载文件或程序集'log4net,Version = 1.2.10.0,Culture = neutral,PublicKeyToken = 1b44e1d426115821' [英] Could not load file or assembly 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821'

查看:899
本文介绍了无法加载文件或程序集'log4net,Version = 1.2.10.0,Culture = neutral,PublicKeyToken = 1b44e1d426115821'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用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的引用(使用第三方dll则无济于事),也可以将程序集重定向设置添加到web.config(app.config)中,以将log4net的指定版本/版本重定向到新版本. /p>

将此部分放置到配置元素下任何位置的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>

有关更多信息,请参见文档页面在msdn 上.

I have added Log4Net in my project using NuGet Package Manager and it is showing Version 2.3 installed on my system.

Here is my config entry:

  <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>

and then reference to this file here

  <log4net configSource="Log4Net.config" />
  <system.serviceModel>

but when I run the website. The following exception is displayed.

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.

I have seen the dll is present in the bin folder but is showing version 1.2.13.0 instead.

How can I change the assembly version?

解决方案

It seems that one of the projects in your solution or maybe some 3rd party dll has been built with different version of log4net. Either you update references to log4net in all projects (with 3rd party dlls this will not help) or you could add assembly redirection setting to the web.config (app.config) that will redirect specified version/versions of log4net to new one.

Put this section to your web.config (app.config) anywhere under configuration element

<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>

For more information look at the documentation page on msdn.

这篇关于无法加载文件或程序集'log4net,Version = 1.2.10.0,Culture = neutral,PublicKeyToken = 1b44e1d426115821'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆