简体   繁体   English

无法加载文件或程序集 'Newtonsoft.Json,版本 = 7.0.0.0

[英]Could not load file or assembly 'Newtonsoft.Json, Version=7.0.0.0

I am facing the error below我正面临以下错误

Could not load file or assembly 'Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies.无法加载文件或程序集“Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed”或其依赖项之一。 The located assembly's manifest definition does not match the assembly reference.定位的程序集的清单定义与程序集引用不匹配。 (Exception from HRESULT: 0x80131040) (来自 HRESULT 的异常:0x80131040)

I could see the below in Web.config我可以在 Web.config 中看到以下内容

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

So I changed it to所以我把它改成

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

In packeges.config I could see the below entry在 packeges.config 我可以看到下面的条目

But still I am facing the same issue.但我仍然面临同样的问题。 Please help请帮忙

A lot of things can go wrong and this error message tells you nothing.很多事情都可能出错,而此错误消息什么也没有告诉您。

But still I am facing the same issue.但我仍然面临同样的问题。

Maybe the easiest way will be to try and reinstall the package.也许最简单的方法是尝试重新安装软件包。

Go to TOOLS > NuGet Package Manager and Select Package Manager Console .转到TOOLS > NuGet Package Manager并选择Package Manager Console Execute the following two commands:执行以下两条命令:

uninstall-package newtonsoft.json -force
install-package newtonsoft.json

If you still get an error after doing this, then what worked for me eventually is that I deleted Json.Net's section from my .config file.如果执行此操作后仍然出现错误,那么最终对我有用的是我从我的 .config 文件中删除了 Json.Net 的部分。 Reinstall brings it back if it's not there and apparently you need to delete it.如果它不存在,则重新安装会将其带回来,显然您需要将其删除。 Until there will be a normal solution in the package itself, I'm afraid this manual step is a must.在包本身有一个正常的解决方案之前,恐怕这个手动步骤是必须的。 In package manager console again execute:在包管理器控制台中再次执行:

Update-Package –reinstall Newtonsoft.Json

Also take a look at your .Net version of the projects in your solution.另请查看解决方案中项目的.Net 版本

This is the Microsoft solution with unloading the project.这是卸载项目的Microsoft 解决方案

I had the same issue.我遇到过同样的问题。 I followed ekostadinov's forced uninstall/reinstall steps, but needed to add one extra step:我遵循了 ekostadinov 的强制卸载/重新安装步骤,但需要添加一个额外的步骤:

I was upgrading my Solution to Framework 4.5.2.我正在将我的解决方案升级到 Framework 4.5.2。 My old Web.Config file had a namespace in the configuration tag.我的旧 Web.Config 文件在配置标签中有一个命名空间。

<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">

I updated to:我更新为:

<configuration>

Then the bindingRedirect should work for whatever version of NewtonSoft you are using:然后 bindingRedirect 应该适用于您使用的任何版本的 NewtonSoft:

<runtime xmlns="">
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <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>
</assemblyBinding>

This can happen if package.config contains 2 same packages name with a different version.如果 package.config 包含 2 个具有不同版本的相同包名称,则会发生这种情况。

For Example,例如,

<package id="System.Spatial" version="5.6.2" targetFramework="net45" />
<package id="System.Spatial" version="5.6.4" targetFramework="net45" />

Thank You.谢谢你。

I had the same issue and doing the uninstall and reinstall didn't help.我遇到了同样的问题,卸载并重新安装没有帮助。 At the time I was trying to install the most current version (10.0.3) of Newtonsoft.Json.当时我正在尝试安装 Newtonsoft.Json 的最新版本 (10.0.3)。 I ended up installing the 7.0.1 version and then ran across another article that suggested copying that .dll to :\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\IDE.我最终安装了 7.0.1 版本,然后看到另一篇建议将该 .dll 复制到 :\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\IDE 的文章。 Which I did.我做的。

Started the install REST API process again and then received a different error.再次启动安装 REST API 过程,然后收到不同的错误。 When attempting to install Microsoft.Rest.ClientRuntime 2.3.2 it failed.尝试安装 Microsoft.Rest.ClientRuntime 2.3.2 时失败。 For this, I just went into NuGet and had it install to the project in which I was installed the REST API.为此,我刚刚进入 NuGet 并将其安装到我安装 REST API 的项目中。

Started the REST API install again and this time it installed.再次启动 REST API 安装,这次安装了。

Oh and if it helps anyone with searches, I was doing the Azure Immersion 02-API App tutorial using VS2015 on Windows Server 2012R2.哦,如果它可以帮助任何人进行搜索,我正在使用 Windows Server 2012R2 上的 VS2015 进行 Azure Immersion 02-API 应用程序教程。

I had the same issue and I got the exception when I was trying to create MassTransit queues:我遇到了同样的问题,并且在尝试创建 MassTransit 队列时遇到了异常:

"Exception: System.TypeInitializationException: The type initializer for 'MassTransit.Serialization.JsonMessageSerializer' threw an exception. ---> System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=12.0.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)"

Solution that worked for me (after spending couple of days reverting several commits):对我有用的解决方案(在花了几天时间恢复了几次提交之后):

  • We had a windows service solution that has .Service project and .XUnitTests project.我们有一个包含 .Service 项目和 .XUnitTests 项目的 Windows 服务解决方案。 Both of them were using a common nuget that has dependency on Newtonsoft.Json.dll.他们都使用了一个依赖于 Newtonsoft.Json.dll 的通用 nuget。 There was no explicit reference to Newtonsoft.Json nuget package in both projects (but we were using 'using Newtonsoft.Json;' namespace in our classes), so the common nuget was using version 9 of Newtonsoft.Json by default.在两个项目中都没有明确引用 Newtonsoft.Json nuget 包(但我们在我们的类中使用了“using Newtonsoft.Json;”命名空间),因此常见的 nuget 默认使用的是 Newtonsoft.Json 的第 9 版。
  • As soon as I installed the Newtonsoft.Json nuget in both .Service and .XUnitTests projects, the common nuget package started using the latest v12 Newtonsoft and that fixed my issue.一旦我在 .Service 和 .XUnitTests 项目中安装了 Newtonsoft.Json nuget,通用 nuget 包就开始使用最新的 v12 Newtonsoft 并解决了我的问题。

Just posting it in here if it saves anyone their valuable time.如果可以节省任何人的宝贵时间,只需将其张贴在这里即可。

most of the time this error happens because of different assemblies are dependent on specific version of some other assembly.大多数情况下,发生此错误的原因是不同的程序集依赖于其他程序集的特定版本。

the easiest fix is to update all packages that are dependent to Newtonsoft.Json using the nuget package manager.最简单的解决方法是使用 nuget 包管理器更新依赖于 Newtonsoft.Json 的所有包。

it will automatically set all config files in your project.它会自动设置项目中的所有配置文件。

I got the same error, and fixed it by doing a 'Clean' on my solution.我遇到了同样的错误,并通过对我的解决方案进行“清理”来修复它。 I'm using Newtonsoft.Json in a UWP app.我在 UWP 应用中使用 Newtonsoft.Json。

Thanks @ekostadinov.谢谢@ekostadinov。 I was able to get it working with the solution from @ekostadinov.我能够使用@ekostadinov 的解决方案使其工作。 In my case, the default Web MVC template had NewtonSoft JSON version 6. I had added a class library and to that I installed NewtonSoft JSON version 9 from Nuget package manager.在我的例子中,默认的 Web MVC 模板有 NewtonSoft JSON 版本 6。我添加了一个类库,并从 Nuget 包管理器安装了 NewtonSoft JSON 版本 9。

I tried removing the reference from my Web project, packages config and dependencies, but still I was getting error.我尝试从我的 Web 项目、包配置和依赖项中删除引用,但仍然出现错误。 Now, I was getting error message saying unable to find Newtonsoft JSON version 6. Initially I was getting error message saying unable to find Newtonsoft JSON version 9.现在,我收到错误消息说无法找到 Newtonsoft JSON 版本 6。最初我收到错误消息说无法找到 Newtonsoft JSON 版本 9。

Then I followed @ekostadinov steps.然后我遵循@ekostadinov 的步骤。

uninstall-package newtonsoft.json -force
install-package newtonsoft.json

I got a warning with respect to a dependency in the package manager console mentioning about a dependency with the version of Web.Grease dll.我收到了关于包管理器控制台中的依赖项的警告,其中提到了 Web.Grease dll 版本的依赖项。 But anyways, it was successful.但无论如何,它是成功的。

Just to double check, I ran the last command mentioned in the above post只是为了仔细检查,我运行了上面帖子中提到的最后一个命令

Update-Package –reinstall Newtonsoft.Json

It ran without any warnings as well.它也没有任何警告地运行。

Now, I am able to use version 9 in all my projects.现在,我可以在所有项目中使用版本 9。

Well, in my case, there were multiple projects in the solution and each was using different version of NewtonSoft.json .好吧,就我而言,解决方案中有多个项目,每个项目都使用不同版本的NewtonSoft.json I had to go ahead and change the version in each project's package.config to match with latest version(Well, it could be any version just that it should be same across the projects).我不得不继续更改每个项目的package.config的版本以匹配最新版本(嗯,它可以是任何版本,只是它应该在项目中相同)。 Once all the package.config point to the same version, all I had to do was一旦所有的 package.config 指向同一个版本,我所要做的就是

Update-Package –reinstall Newtonsoft.Json

Now, watch out I also had to manually change the version on web.config assembly entry in one of the projects.现在,请注意我还必须手动更改其中一个项目中 web.config 程序集条目的版本。 but that did the job.但这做到了。

My be it is too late but hopefully, it might be useful for the people supporting old projects.我为时已晚,但希望它对支持旧项目的人有用。

Add dependentAssembly tag and give the version number in oldVersion for which you are getting error.添加dependentAssembly 标记并在 oldVersion 中给出您遇到错误的版本号。 In my case it was giving the error for version 6.0.0 Give the installed version value in newVersion as mentioned below:在我的情况下,它给出了版本 6.0.0 的错误 在 newVersion 中给出已安装的版本值,如下所述:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Newtonsoft.Json版本8.0.2无法加载文件或程序集错误 - Newtonsoft.Json version 8.0.2 Could not load file or assembly Error 无法加载文件或程序集 &#39;Newtonsoft.Json,版本 = 12.0.0.0? - Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0? 无法加载文件或程序集 &#39;Newtonsoft.Json,版本 = 10.0.0.0 - Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0 无法加载文件或程序集“Newtonsoft.Json”版本=11.0.0.0 - Could not load file or assembly 'Newtonsoft.Json' Version=11.0.0.0 无法加载文件或程序集'Newtonsoft.Json,版本 = 3.5.0.0 - Could not load file or assembly 'Newtonsoft.Json, Version=3.5.0.0 无法加载文件或程序集“NewtonSoft.Json,版本=12.0.0.0” - Could not load file or assembly 'NewtonSoft.Json, Version=12.0.0.0' 无法加载文件或程序集Newtonsoft.json版本6.0.0.0 - Could not load file or assembly Newtonsoft.json Version 6.0.0.0 无法加载文件或程序集“ Newtonsoft.Json” - Could not load file or assembly 'Newtonsoft.Json' 无法加载文件或程序集“newtonsoft.json” - could not load file or assembly 'newtonsoft.json' CacheManager.Serialization.Json“无法加载文件或程序集&#39;Newtonsoft.Json,Version = 8.0.0.0” - CacheManager.Serialization.Json “Could not load file or assembly 'Newtonsoft.Json, Version=8.0.0.0”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM