无法加载程序集问题

时间:2017-11-09 07:58:14

标签: c# visual-studio-2013

我遇到了以下问题

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

更多信息

=== Pre-bind state information ===
LOG: DisplayName = NLog, Version=2.0.1.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c
(Fully-specified)
LOG: Appbase = file:///C:/MyProj/XX.XXX.TempProj/
LOG: Initial PrivatePath = C:\MyProj\XX.XXX.TempProj\bin
 Calling assembly : MyProj.CallingLayer, Version=1.2.1.1, Culture=neutral, PublicKeyToken=57732cb8f5e77948.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\MyProj\XX.XXX.TempProj\web.config
LOG: Using host configuration file: \\corp.corpcommon.com\users\EXXXX\MY Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: NLog, Version=2.0.1.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c
LOG: Attempting download of new URL file:///C:/Users/EXXXX/AppData/Local/Temp/Temporary ASP.NET Files/vs/39ab25b3/cbea207a/NLog.DLL.
LOG: Attempting download of new URL file:///C:/Users/EXXXX/AppData/Local/Temp/Temporary ASP.NET Files/vs/39ab25b3/cbea207a/NLog/NLog.DLL.
LOG: Attempting download of new URL file:///C:/MyProj/XX.XXX.TempProj/bin/NLog.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

我尝试使用nuget安装和卸载Nlog,但它没有帮助。我试图改变web.config,如

<dependentAssembly>
    <assemblyIdentity name="NLog" publicKeyToken="5120e14c03d0593c" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="4.0.0.0" />
  </dependentAssembly>

我使用的是Nlog 4.0版

1 个答案:

答案 0 :(得分:2)

正如您的错误消息所示 - 您在项目中使用的某些DLL是针对NLOG版本 2.0.1.0 编译的。您的应用程序似乎使用NLOG版本4.0.0.0。您正确地尝试使用绑定重定向,但绑定重定向表示“将0.0.0.0和 2.0.0.0 之间的所有版本的程序集NLOG重定向到版本4.0.0.0。版本2.0.1.0大于2.0。 0.0因此它没有被重定向。例如,你可以参考这个问题来学习更多关于绑定重定向的信息:Assembly Binding redirect: How and Why?