ChatGPT解决这个技术问题 Extra ChatGPT

无法加载文件或程序集“Newtonsoft.Json”或其依赖项之一。清单定义与程序集引用不匹配

搜索后我尝试过的事情:

在 Web.Config 中对旧版本进行绑定: 编辑我的 .csproj 文件以确保只有一个 Newtonsoft 参考 ..\packages\Newtonsoft.Json.6.0.1\lib\net45\Newtonsoft.Json.dll False True < /Reference> 在我的计算机上搜索每个 Newtonsoft.Json.dll 并删除每个非 6.0.1 版本并删除我的临时文件夹的内容 在 nuget 管理器控制台中修复/重新安装包

它在构建时成功,但在访问站点时出现错误。

编辑

好的,所以我尝试像每个 nuget 包一样重新安装,它似乎已经添加了 newtonsoft.json.dll 的 4.5 版本,但我得到了同样的错误。我的项目的目标框架是 .NET 4.5.1,这是我现在得到的堆栈跟踪:

“/”应用程序中的服务器错误。无法加载文件或程序集 Newtonsoft.Json 或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。 (来自 HRESULT 的异常:0x80131040) 说明:在执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。异常详细信息:System.IO.FileLoadException:无法加载文件或程序集 Newtonsoft.Json 或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。 (来自 HRESULT 的异常:0x80131040)源错误:在执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常起源和位置的信息。程序集加载跟踪:以下信息有助于确定无法加载程序集 Newtonsoft.Json 的原因。

=== Pre-bind state information ===
LOG: DisplayName = Newtonsoft.Json
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: Newtonsoft.Json | Domain ID: 2
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///c:/users/user/documents/visual studio 2013/Projects/foo/bar/
LOG: Initial PrivatePath = c:\users\user\documents\visual studio 2013\Projects\foo\bar\bin
Calling assembly : (Unknown).
 ===
LOG: This bind starts in default load context.
LOG: Using application configuration file: c:\users\user\documents\visual studio 2013\Projects\foo\bar\web.config
LOG: Using host configuration file: C:\Users\user\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Users/user/AppData/Local/Temp/1/Temporary ASP.NET Files/root/48686d37/9d7a6572/Newtonsoft.Json.DLL.
LOG: Attempting download of new URL file:///C:/Users/user/AppData/Local/Temp/1/Temporary ASP.NET Files/root/48686d37/9d7a6572/Newtonsoft.Json/Newtonsoft.Json.DLL.
LOG: Attempting download of new URL file:///c:/users/user/documents/visual studio 2013/Projects/foo/bar/bin/Newtonsoft.Json.DLL.
LOG: Using application configuration file: c:\users\user\documents\visual studio 2013\Projects\foo\bar\web.config
LOG: Using host configuration file: C:\Users\user\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 6.0.1.0.
LOG: Post-policy reference: Newtonsoft.Json, Version=6.0.1.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
LOG: Attempting download of new URL file:///C:/Users/user/AppData/Local/Temp/1/Temporary ASP.NET Files/root/48686d37/9d7a6572/Newtonsoft.Json.DLL.
LOG: Attempting download of new URL file:///C:/Users/user/AppData/Local/Temp/1/Temporary ASP.NET Files/root/48686d37/9d7a6572/Newtonsoft.Json/Newtonsoft.Json.DLL.
LOG: Attempting download of new URL file:///c:/users/user/documents/visual studio 2013/Projects/foo/bar/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.

堆栈跟踪:

[FileLoadException: Could not load file or assembly 'Newtonsoft.Json' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]

[FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=6.0.1.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)]
       System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
       System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +34
       System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +152
       System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +77
       System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +16
       System.Reflection.Assembly.Load(String assemblyString) +28
       System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +38

[ConfigurationErrorsException: Could not load file or assembly 'Newtonsoft.Json, Version=6.0.1.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)]
       System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +752
       System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +218
       System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +130
        System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +170
       System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +91
       System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +285
       System.Web.Compilation.BuildManager.ExecutePreAppStart() +153
       System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +516

[HttpException (0x80004005): Could not load file or assembly 'Newtonsoft.Json, Version=6.0.1.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)]
       System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9913572
       System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
       System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18408
好的,我想我现在可以开始工作了。我删除了我机器上所有不是我能找到的最新版本的 Newtonsoft.Json.dll,确保我在 NuGet 中拥有最新版本,并构建它并确保它是 bin 文件夹中的最新版本,并且我将更改保留在 web.config 和 .csproj 中。现在我遇到了另一个错误,所以它必须工作......
为您的问题添加答案,以便人们可以看到它已得到解决?并将其标记为解决方案
即使在今天(2016 年 3 月 1 日)版本 8.0.2,我也遇到了这个问题的某些版本。它正在尝试加载版本 6.0.0。我的解决方案中没有文件引用 6.0.0。没有版本 6.0.0。 .dll 在我的解决方案区域的任何地方。我的计算机上有许多 newtonsoft.json.dll 的副本,有各种版本,它们被安装的我不想弄乱的第 3 方软件使用。除了删除所有这些副本之外,我已经尝试了整个线程中提到的所有解决方案,但没有任何效果。
当我将一个项目的引用添加到另一个项目时,我也遇到了 newtonsoft-json 的错误消息,但是在修复了两个问题的相同 .Net Framework 后,项目中的 .Net Framework 不同。但我无法理解为什么它显示 newtonsoft-json 相关错误而不是 Framework 错误消息。
在所有项目中安装相同版本的 Newtonsoft.Json,即使他们不使用它。

u
user1477388

为了解决这个问题,我通过运行以下命令并检查结果来确保我的所有项目都使用相同的版本:

update-package Newtonsoft.Json -reinstall

最后,我从 web.config 中删除了以下内容:

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

如果要确保所有 Newtonsoft.Json 包的版本相同,可以像这样指定版本:

update-package Newtonsoft.Json -version 6.0.0 -reinstall

注意:要在 Visual Studio 中打开 PMC,请单击工具 -> Nuget 包管理器 -> 包管理器控制台。谢谢@罗斯!


只需运行重新安装命令对我有用。我不需要修改 web.config。
我只需要添加 标记即可消除此错误。
我必须提供 -version,但省略 -reinstall 标志以使其适用于我的情况。
我使用的是最新版本 9.0.1,但它显示相同的错误。然后我检查了csproj文件中的版本,它是9.0.0.0,将它添加到我的web.config中,问题就解决了。 1. 确保 csproj 中的版本与 web.config 中的版本相同 2. 注意版本号,当实际版本为 x.0.0.0 时,它可能会说 x.0.1,x 可以是 6 或 9 或任何它.
请注意,要在 VS2017 中运行命令,您可以进入工具 -> Nuget 包管理器 -> 包管理器控制台
G
Gergo Erdosi

我正在使用 Newtonsoft.Json v6.0.3,但这是我必须在我的 Web.config 文件中执行的操作:

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

请注意,即使我使用的是 6.0.3,我也必须输入 newVersion="6.0.0.0"

在我的 packages.config 文件中,我有:

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

正如一个注释,我尝试卸载/删除/删除我能找到的与 Newtonsoft.Json 相关的所有内容,然后使用 Nuget 重新安装它,但仍然收到上述错误。直到我进行了我提到的更改,我才能够让它正常工作。
我遇到了这个问题,并使用了 Assembly Binding Log Viewer 来帮助诊断它。程序集绑定器将 v6.0.3 Newtonsoft.Json.dll 报告为 v6.0.0.0,因此当我将其配置为 6.0.3 时重定向会失败。
“注意”行帮助我。我最初在 bindingRedirect 中将 9.0.1.19813 作为 newVersion,因为这就是 DLL 所说的。这就是我现在所拥有的: False
三年后,我也有同样的经历。将新版本从“12.0.1.0”更改为“12.0.0.0”解决了这个问题。
S
Samuel

在确保我的计算机在所有位置都具有相同的版本并且我的项目都指向相同的参考路径之后,我尝试了以下操作。我还确保旧版本的绑定是他们的并且绑定到我拥有的当前版本的 dll。

我在具有严格框架的环境中工作,并且框架团队经常用不同的 dll 打乱版本控制。

我解决此问题的方法是在 Visual Studio (2013) 中运行包管理器控制台。从那里我运行了以下命令:

update-package Newtonsoft.Json -reinstall

其次是

update-package Newtonsoft.Json

这经历并更新了我所有的配置文件和相关的项目文件。强制它们使用相同版本的 dll。最初是 4.5 版,然后再次更新以获取最新版本。


这是为我解决问题的更新。我的项目已更新到 Newtonsoft 7.0 版。
为我工作。完成此操作后,请务必注意确保您的 package.config 和 web.config 文件具有匹配的版本。
从 NuGet 包管理器控制台完成后为我工作,谢谢!
S
S__

我有同样的错误信息,就像你提到的,这是由于引用了不同版本的 Newtonsoft.Json.dll。

我的 MVC 解决方案中的一些项目使用了该 dll 版本 4 的 NuGet 包。

然后,我添加了一个 NuGet 包(在我的例子中是 Salesforce),它带来了 Newtonsoft.Json 版本 6,作为其中一个项目的依赖项。这就是引发我问题的原因。

为了清理,我使用解决方案的 NuGet 包管理器中的更新部分(关闭工具菜单或解决方案右键单击)来更新整个解决方案中的 Json.Net 包,因此它对于所有项目都是相同的版本。

之后,我检查了 App Config 文件以确保任何绑定重定向行都转到我选择的版本,如下所示。

<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />

如果 DLL 对同一个 MVC 应用程序的不同版本的 Newtonsoft.Json 有依赖关系怎么办?这就是我卡住的地方。
使用 NuGet 包管理器中的合并选项确保版本不会分开。
n
noobieDev

好的,我想我现在可以开始工作了。我删除了我机器上所有不是我能找到的最新版本的 Newtonsoft.Json.dll,确保我在 NuGet 中拥有最新版本,并构建它并确保它是 bin 文件夹中的最新版本,并且我将更改保留在 web.config 和 .csproj 中。现在我遇到了另一个错误,所以它必须工作..


你是如何在你的机器上找到所有位置的?
当我通过团队基础服务器将项目添加到我的电脑时,我也遇到了错误。我将 newtonsoft 的引用添加到我的解决方案中。它不起作用。然后我通过 nuget 包管理器安装 json.net (newtonsoft.json)。现在它是工作正常。
它在 bin 文件夹文件名中 - Newtonsoft.Json.dll 删除此文件并重新安装软件包,或者只安装较低版本并使用 NuGet-Solution 重新安装正确的版本
W
Willy David Jr

通过在我的 web.config 上将这部分注释掉,解决了我的问题:

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

但是当然,您需要通过在包管理器控制台中执行此操作来确保您已更新或拥有正确的版本:

update-package Newtonsoft.Json -reinstall

A
Ali Kleit

经过几个小时的努力……我做了以下事情:

网络配置

<runtime>

  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

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

    <!-- other assemblies... -->

  </assemblyBinding>
</runtime>

输入正确的新版本和旧版本号的关键是打开项目的 References 找到包转到其属性或点击 alt + enter

在使用 Manage NuGet 进行探索时,您会发现一个部分 Version,在我的例子中是 12.0.0.0,而实际上是 12.0.3

所以你需要从参考属性中选择包的版本(在我的例子中是 12.0.0.0)

最后,cleanrebuild 项目(您可能想要删除之前的 binobj 文件夹)。

你可能会遇到其他包依赖问题,我为所有人做了这件事,他们工作了。


删除 bin 和 obj 文件夹对我有用。
J
Jineesh Uvantavida

您可以通过在 web.config 文件中添加以下行来解决此问题。

 <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

d
daniloquio

就我而言,这只是一个问题:

Tools -> NuGet Package Manager -> Package Manager Settings -> Clear Cache

问题是我重新映射 TFS 文件夹时引起的。


A
Azeem

我已经尝试了 Oleg 的步骤,它们适用于我同样的情况。

脚步:

在包管理器中运行 update-package Newtonsoft.Json -reinstall。通过启用查看隐藏文件并删除 bin 文件夹来删除您的 bin。关闭您的 Visual Studio 并重新打开它。现在再次运行您的项目。我相信应该没问题!


S
Shaulian

真正帮助我的是关闭 Resharper 构建并在我的项目中使用 VisualStudio Re-Build 选项。


你是怎么做到的?
在 Resharper 的选项中:工具 -> ReSharper 构建 -> 构建引擎 - 选择“Visual Studio”
我不久前安装了试用版(我想大约一个月),然后我也禁用了扩展。我没有在工具中看到它,所以希望我没事。
G
Goda Kotb

从工具>>NuGet 包管理器>>管理包以将所有解决方案的 Newtonsoft.Json 更新到最新版本


c
ch2o

如果您正在使用某种颠覆:删除项目并重新下载它,它对我有用:S


很长的路要走,但我不得不这样做,因为没有其他解决方案对我有用
C
Community

我在引用 MVC 5 项目的测试项目上遇到了同样的问题。这发生在我与 MVC 5 项目合并之后。我通过安装 Visual Studio 2012 更新来修复它,正如 Andre 的回复中解释的 here

在您的 Visual Studio 中,转到工具 > 扩展和更新 在左侧的手风琴列表中选择“更新”。选择“产品更新”。更新到最新版本

工具> 扩展和更新

在左侧的手风琴列表中选择“更新”。

选择“产品更新”。

更新到最新版本


虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接答案可能会失效
我的问题已通过此解决方案得到解决,谢谢!我安装了 8.0.1 版本,但在我更新到 VS2013 更新 5 之前它没有工作
m
mesut

我不知道为什么,但在我的情况下,即使我从项目中删除 bin 文件夹,当我构建项目时它会复制旧版本的 newtonsoft.json,我从包文件夹中复制了新版本的 dll,它现在可以解决。


我有一个类似的问题。在我的解决方案中,我有一个测试项目。测试项目在 bin 中获取版本 9,但我正在测试的项目具有版本 12。我将版本 12 从测试项目的 bin 文件夹复制到测试的 bin 文件夹。
C
Community

如果这些都不起作用,请检查以下答案:

https://stackoverflow.com/a/12011221/150370

TL;DR:从配置文件中的 configuration 标记中删除 xml 命名空间。否则绑定重定向将被忽略)


I
Ivan Ruski

在某些情况下,如果您删除 BinObj 文件夹将解决此问题。


j
jspinella

好吧,所以我想要做的是将我的答案添加到这个长长的列表中,而不是创建一个重复的问题......

如果您在 2019 年使用 .NET Core 3.0(此时为预览版),则解决方案是确保所有项目都针对相同的 .NET Core 版本(在我的情况下为 3.0)。我想我有一个针对 2.1 的解决方案项目,其余的都是 2.2,所以我可能会坚持使用 2.2...

我什至没有在任何项目中安装 Newtonsoft.Json,自然将它添加到它们并不能解决问题。

如果您的解决方案中有 .NET Standard 类库或 w/e,则它们不需要使用相同的版本,尽管它们可能应该是您可以使用的最新版本。例如,我的 .NET Standard 类库是 2.2,因为还没有 .NET Standard 3.0。


我怀疑 NET 版本是我的问题,但这个解决方案不起作用:我有一个针对 net6 的应用程序,以及针对 framework48 的应用程序和针对标准 2.0 的共享库。框架应用程序虽然不直接使用 json,但构建正在将框架 newtonsoft 库推入构建中,我无法将标准 newtonsoft 放入:(
对于您在 Framework 4.8 - .NET 6 环境中遇到的问题,我并不感到惊讶。您使用了正确的 .NET Standard (2.0) 来支持两者,但自从 System.Text.Json 发布以来,Newtonsoft 一直是通配符。您可能应该为您的问题创建一个新问题,我想不出任何建议给您:(
Z
Zafer Sernikli

没有一个答案,包括选中的答案对我不起作用。

解决方案要简单得多。我首先从我的 BUS 层中删除了引用。然后从项目中删除 dll(以确保它消失了),然后从 nuget packeges 重新安装 JSON.NET。而且,棘手的部分是“将其关闭再打开”。

我刚刚重新启动了视觉工作室,它在那里工作!

因此,如果您尽一切可能尝试但仍然无法解决问题,只需尝试关闭并重新打开 Visual Studio,它可能会有所帮助。


我认为Simple是讽刺。
A
Alok Kumar

我通过在 bin 文件夹中删除较低版本的 Newtonsoft.json.dll 并添加 Newtonsoft.json.dll V6.0.0.0 并删除了以下 web.config 元素来解决它

<dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed"/>
    <bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="5.0.8"/>
</dependentAssembly>

d
datoml

我在 dotnet core 上遇到了同样的问题,并设法通过清除 NuGet 缓存来解决它。

打开powershell并输入以下命令。

dotnet nuget locals all --clear

然后我关闭了 Visual Studio,再次打开它并在包管理器控制台中输入以下命令:

Update-Package

NuGet 现在应该恢复所有包并再次填充 nuget 缓存。

之后,我能够在 Linux 容器中构建和启动我的 dotnet core webapi。


E
Er.Imran Shaikh

解决我的问题的解决方案是

转到引用->右键单击 Newtonsoft.json--转到属性并检查版本

这个相同的版本应该在

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

O
Odeyinka Olubunmi

简单的步骤。 (1)在包管理器中运行“update-package Newtonsoft.Json -reinstall”。

(2)通过启用查看隐藏文件并删除bin文件夹来删除您的bin。

(3)关闭您的视觉工作室并重新打开它。

(4) 现在再次运行您的项目。我相信应该没问题


M
Mike S

我遇到了这个问题,因为我有:项目 A(桌面 .exe)引用项目 B(便携式 .dll)。 A & B 有不同版本的 JSON.Net,因此存在加载器冲突。一旦我使 JSON.net 的所有版本都相同,它就可以工作了。 (这实际上是上述一些解决方案正在做的事情——我只是在说明它为什么有效)


F
Fredrik Stolpe

我最近在和较旧的项目中遇到了这个问题。

在检查了 bin 文件夹中实际存在的 dll 版本后,我设法找到了问题所在。

我有一个构建后脚本,它将依赖程序集从 dll 库文件夹复制到 bin 文件夹。 nuget 之前的常见设置。

因此,每次我构建构建后脚本时,都会将正确版本的 Json.net 替换为旧版本


M
Mcole1976

我遇到了完全相同的问题,我的 Visual Studio 13 默认库是 4.5,所以我有 2 个解决方案,一个是在 webconfig 文件中删除对此的引用。这是最后的手段,它确实有效。

错误消息指出此位置 /Projects/foo/bar/bin/Newtonsoft.Json.DLL 存在问题。 DLL 在哪里!基本属性检查告诉我它是 4.5.0.0 或类似的,所以我将 webconfig 更改为查找 4.5 并使用 4.5。


D
Daniel Haselden

这些选项都不适合我,最终它是;

测试 > 测试设置 > *.testrunconfig

我不得不添加一个新行

<DeploymentItem filename="packages\Newtonsoft.Json.4.5.8\lib\net40\Newtonsoft.Json.dll" />

确保路径和版本适合您的设置。


C
CaffeineDrivenDevelopment

我遇到过同样的问题。我创建了一个 web api 项目,然后将其从 .net 4.5.1 升级到 .net 4.6.1。关闭 IDE、停止 IIS 并删除 C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\ 目录的内容修复了该问题。

高温高压


A
Alexander P. Brown

通过刷新 NuGet 包或对项目执行“清理”,我无法解决这个问题。它是通过手动清除“obj”文件夹来解决的。


佚名

这是我对这个问题的解决方案,请确保 appconfig 或 packageconfig 中的版本号与您参考中的参考版本相同。请参阅here