错误的.NET程序集版本被复制到Web窗体bin目录

问题描述 投票:0回答:1

我正在使用ASP.NET Web Forms网站,并经常获得如下运行时异常:

Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' 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 = Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
 (Fully-specified)
LOG: Appbase = file:///C:/Code/MyProject/
LOG: Initial PrivatePath = C:\Code\MyProject\bin
Calling assembly : System.Net.Http.Formatting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Code\MyProject\web.config
LOG: Using host configuration file: \\foo\bar\Profile.v2\simonm\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Redirect found in application configuration file: 4.5.0.0 redirected to 11.0.0.0.
LOG: Post-policy reference: Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
LOG: Attempting download of new URL file:///C:/Users/simonm/AppData/Local/Temp/Temporary ASP.NET Files/vs/8d6ca9e7/1d38a78a/Newtonsoft.Json.DLL.
LOG: Attempting download of new URL file:///C:/Users/simonm/AppData/Local/Temp/Temporary ASP.NET Files/vs/8d6ca9e7/1d38a78a/Newtonsoft.Json/Newtonsoft.Json.DLL.
LOG: Attempting download of new URL file:///C:/Code/MyProject/bin/Newtonsoft.Json.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

它们总是因为程序集的“错误”版本(它似乎总是似乎是Newtonsoft.Json)被复制到Bin目录,尽管站点根目录中的packages.config具有:

<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net45" />

并且web.config包含:

<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
</dependentAssembly>

有人可以解释是什么规定哪个程序集被复制到Bin目录,为什么会一直发生以及如何防止它在将来发生?

asp.net webforms nuget web-config .net-assembly
1个回答
1
投票

我猜,你使用过的一些框架/库正在使用不同版本的Newtonsoft.Json。首先,检查您的框架/库是否需要不同版本的Newtonsoft.Json库。

当您检测到哪个是(最低)所需版本的Newtonsoft.Json时,请尝试通过Nuget重新安装此版本。

© www.soinside.com 2019 - 2024. All rights reserved.