Подтвердить что ты не робот

Не удалось загрузить файл или сборку 'log4net, Version = 1.2.10.0, Culture = neutral, PublicKeyToken = 1b44e1d426115821'

Я добавил Log4Net в свой проект с помощью NuGet Package Manager, и он показывает версию 2.3, установленную в моей системе.

Вот моя запись в config:

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

Как изменить версию сборки?

4b9b3361

Ответ 1

Похоже, что один из проектов в вашем решении или, возможно, какая-то сторонняя dll была построена с другой версией log4net. Либо вы обновляете ссылки на log4net во всех проектах (с помощью 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>

Для получения дополнительной информации см. страницу документации в msdn.