无法加载程序集问题

unable to load assembly issue

我遇到了以下问题

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

如您的错误消息所述 - 您在项目中使用的某些 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 所以它没有被重定向。你可以参考这个问题来了解更多关于绑定重定向的信息:.