2015-06-03 15 views
10

Tôi đã thêm Log4Net vào dự án của mình bằng NuGet Package Manager và đang hiển thị Phiên bản 2.3 được cài đặt trên hệ thống của tôi.Không thể tải tệp hoặc lắp ráp 'log4net, Phiên bản = 1.2.10.0, Văn hóa = trung lập, PublicKeyToken = 1b44e1d426115821'

Đây là entry cấu hình của tôi:

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

và sau đó tham khảo để tập tin này ở đây

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

nhưng khi tôi chạy trang web. Ngoại lệ sau đây được hiển thị.

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. 

Tôi đã thấy dll có trong thư mục bin nhưng đang hiển thị phiên bản 1.2.13.0 thay thế.

Làm cách nào để thay đổi phiên bản lắp ráp?

Trả lời

8

Dường như một trong các dự án trong giải pháp của bạn hoặc có thể một số dll bên thứ 3 đã được tạo bằng phiên bản khác của log4net. Hoặc bạn cập nhật các tham chiếu tới log4net trong tất cả các dự án (với các dll bên thứ 3 sẽ không giúp ích gì) hoặc bạn có thể thêm cài đặt chuyển hướng assembly vào web.config (app.config) sẽ chuyển hướng phiên bản/phiên bản đã được chỉ định của log4net sang log4net mới.

Đặt phần này để web.config của bạn (app.config) bất cứ nơi nào trong thành phần cấu hình

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

Để biết thêm thông tin nhìn vào documentation page on msdn.

+0

Điều đó có vẻ là câu trả lời đúng, nhưng tôi đã thực hiện điều đó bằng cách hạ cấp 'Log4Net' thành' 1.2.10.0' và mọi thứ hoạt động tốt. Bây giờ tôi không thể làm điều đó, bởi vì tôi đã chuyển bản vá này sang sản xuất. Tôi vẫn đang đánh dấu câu trả lời của bạn để tham khảo trong tương lai (đối với những người khác) –

Các vấn đề liên quan