无法加载文件或程序集的Newtonsoft。Json、Version = 4.5.0.0文化=中立,都30 ad4fe6b2a6aeed

时间:2021-07-02 17:07:44

I am getting the Error

我弄错了。

System.IO.FileLoadException : 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)

先。FileLoadException:不能加载文件或程序集的Newtonsoft。Json, Version=4.5.0.0, Culture=中性,PublicKeyToken=30ad4fe6b2a6aeed,或它的一个依赖项。定位组件的清单定义与程序集引用不匹配。(从HRESULT例外:0 x80131040)

for my CI build

为我的CI构建

Solution which I tried

解决方案,我试着

<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>

It also did not work

它也不起作用。

39 个解决方案

#1


188  

In package manager console execute: Update-Package –reinstall Newtonsoft.Json.

在包管理器控制台执行:更新包-重新安装Newtonsoft.Json。

UPDATE

更新

I originally posted this as a comment but as @OwenBlacker suggested I'll just put it here:

我最初把这个作为评论,但是@OwenBlacker建议我把它写在这里:

If you still get an error after doing this, then what worked for me eventually is that I deleted Json.Net's <dependentAssembly> section from my .config file. 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.

如果您在执行完这个操作之后仍然有错误,那么最终对我有效的是我删除了Json。从我的.config文件中,Net的 部分。如果它不在那里,重新安装就会返回,显然你需要删除它。除非软件包本身有一个正常的解决方案,否则我恐怕这个手动步骤是必须的。

Note: Please read the comments below before doing this.

注意:在做这个之前请先阅读下面的评论。

As per René's comment below BE AWARE that the command posted in the answer will reinstall the package in every project in your solution. So if you use the Newtonsoft.Json package in several projects and maybe use different versions, just executing the above command might have unwanted consequences.

根据Rene的评论,请注意,在答案中发布的命令将在解决方案中的每个项目中重新安装包。如果你使用Newtonsoft。在多个项目中使用Json包,可能使用不同的版本,执行上述命令可能会产生不必要的后果。

#2


103  

To everyone having problems with Newtonsoft.Json v4.5 version try using this in web.config or app.config:

对每个人都有新的问题。Json v4.5版本尝试在web上使用它。配置或app.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-6.0.0.0" newVersion="6.0.0.0"/>
       </dependentAssembly>
    </assemblyBinding>
</runtime>

IMPORTANT: Check that the configuration tag of your config file has no namespace attribute (as suggested in https://*.com/a/12011221/150370). Otherwise, assemblyBinding tags will be ignored.

重要:检查配置文件的配置标记没有名称空间属性(如https://*.com/a/12011221/150370所建议的)。否则,将忽略汇编绑定标记。

#3


27  

The key point is referencing right version in your config file.

关键是在配置文件中引用正确的版本。

Steps;

步骤;

1- look at what is the version of your Newtonsoft.Json.dll in the project reference property what ever the version in your package folder (For example mine is 7.0.1 and the reference Version is 7.0.0.0)

1-看看你的Newtonsoft.Json版本是什么。项目引用属性中的dll文件(例如,我的包文件夹中的版本为7.0.1,参考版本为7.0.0.0)。

2- look at what the project expect from you in the exception (mine is 6.0.0.0)

2-看看这个项目对你的期望是什么(我的是6.0.0.0)

3- Add dependent assembly to your config file as it should be..

3-将附属程序集添加到配置文件中。

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

#4


23  

I had no luck with any of the solutions presented here (uninstalling, reinstalling, deleting references, creating bindingRedirects etc.) I had to go back to an old version of Newtonsoft. Version 5.0.6 had been working before, so I tried that one. I had to enter these two commands in the Package Console:

我在这里没有遇到任何的解决方案(卸载、重新安装、删除引用、创建bindingre等),我必须回到旧版本的Newtonsoft。版本5.0.6之前一直在工作,所以我尝试了这个。我必须在包控制台输入这两个命令:

uninstall-package newtonsoft.json -force

uninstall-package newtonsoft。json force

install-package newtonsoft.json -version "5.0.6"

安装包newtonsoft。json - version“5.0.6”

The -force option in the first command is required to force the uninstall. Dependencies with other assemblies prevent the uninstall without it.

第一个命令中的-force选项需要强制卸载。与其他程序集的依赖关系可以防止没有它的卸载。

#5


20  

I fixed the problem adding this binding redirect to my .config file:

我修正了将这个绑定重定向到.config文件的问题:

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

The error message complains about not finding version 4.5.0.0, the current version of Newtonsoft.Json is 6.0.0.0 so the redirect should go from 4.5 to 6.0, not viceversa

错误消息抱怨没有找到版本4.5.0.0版本,当前版本的Newtonsoft。Json是6.0.0.0,因此重定向应该从4.5到6.0,而不是viceversa。

#6


19  

I think you are pointing to the wrong target, change it to 4.5 instead of 6.0

我认为你指向错误的目标,将它改为4.5,而不是6.0。

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

This should work.

这应该工作。

#7


16  

I've spend couple of days trying to resolve this frustrating issue. I've tried pretty much everything that can be found on the web. Finally I found that this error could be caused (like in my case) by the different target .Net project versions (4.5 and 4.5.1) in one solution. The steps bellow fixed it for me:

我花了几天时间试图解决这个令人沮丧的问题。我已经试过了所有能在网上找到的东西。最后,我发现在一个解决方案中,不同的目标. net项目版本(4.5和4.5.1)可能会导致这个错误(就像我的例子一样)。下面的步骤为我解决了这个问题:

  1. Double check the .Net version of every project that's in your solution. Just right click on project and go to Properties.
  2. 仔细检查你的解决方案中每个项目的。net版本。右键点击项目,然后进入属性。

无法加载文件或程序集的Newtonsoft。Json、Version = 4.5.0.0文化=中立,都30 ad4fe6b2a6aeed

  1. If possible set the same .Net version for all projects. If not at least try to change the Startup project one (for me this was the one causing the issues).

    如果可能,为所有项目设置相同的。net版本。如果不是至少尝试改变启动项目一(对我来说这是导致问题的原因)。

  2. Remove all Newtonsoft.Json packs from the solution.

    删除所有Newtonsoft。来自解决方案的Json包。

    uninstall-package newtonsoft.json -force

    uninstall-package newtonsoft。json force

  3. Update all Newtonsoft.Json versions in all packages.config files, like so

    更新所有Newtonsoft。所有包中的Json版本。配置文件

    <package id="Newtonsoft.Json" version="7.0.1" targetFramework="net451" />

    <包id = " newtonsoft。json version=" 7.0.1 " targetframework=" net451 ">

  4. Reinstall Newtonsoft.Json from "Package Manager Console" with:

    重新安装Newtonsoft。来自“Package Manager Console”的Json:

    install-package newtonsoft.json

    安装包newtonsoft.json

  5. Rebuild the solution

    重建方案

(Optional) 7. If you changed the Startup project, return it again

(可选)7。如果您更改了启动项目,请再次返回。

#8


9  

Remove the Newtonsoft.Json assembly from the project reference and add it again. You probably deleted or replaced the dll by accident.

删除Newtonsoft。来自项目引用的Json程序集,并再次添加它。您可能会意外删除或替换dll。

#9


9  

I was writing a WebApi REST service client, so for me this error was caused by adding References to the System.Net.Http and System.Net.Http.Formatting assemblies manually via Add Reference, when I should have added the Microsoft.AspNet.WebApi.Client package via NuGet. See also this answer to another question.

我正在编写一个WebApi REST服务客户端,所以对于我来说,这个错误是由于添加了对System.Net的引用而引起的。Http和System.Net.Http。通过添加引用手动格式化程序集,当我应该添加Microsoft.AspNet.WebApi时。客户端通过NuGet包。再看另一个问题的答案。

#10


9  

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

Did the trick for me :)

给我的窍门:)

#11


7  

if you using multiple project in same solution and library of the one other check is all projects has same version of Newtonsoft.Json

如果您在同一解决方案中使用多个项目,而另一个检查的库中使用的是所有项目都具有相同版本的Newtonsoft.Json。

#12


6  

Normally adding the binding redirect should solve this problem, but it was not working for me. After a few hours of banging my head against the wall, I realized that there was an xmlns attribute causing problems in my web.config. After removing the xmlns attribute from the configuration node in Web.config, the binding redirects worked as expected.

通常添加绑定重定向应该可以解决这个问题,但是它对我不起作用。几小时后,我的头撞到墙上,我意识到在我的web.config中有一个xmlns属性导致问题。将xmlns属性从Web的配置节点中删除之后。配置,绑定重定向按预期工作。

http://www.davepaquette.com/archive/2014/10/02/could-not-load-file-or-assembly-newtonsoft-json-version4-5-0-0.aspx

http://www.davepaquette.com/archive/2014/10/02/could -不-负载-文件-或-装配- newtonsoft - json - version4 - 5 - 0 - 0. aspx

#13


5  

Deploy the correct version to the CI machine

将正确的版本部署到CI机器。

This is telling you that the assembly loader found a different version of the Newtonsoft.Json assembly, that does not match the reference you created in your project. To load the assembly correctly, you must either deploy the assembly side by side with your compiled code, or install the correct version of the assembly in the destination machine (i.e. in the GAC).

这告诉您,程序集加载器找到了不同版本的Newtonsoft。Json程序集与您在项目中创建的引用不匹配。要正确地加载程序集,您必须使用编译后的代码部署程序集,或者在目标机器(即GAC)中安装正确的程序集版本。

Alternative: make sure the configuration is in the correct file

选择:确保配置在正确的文件中。

If you want to keep the current solution, and load an assembly with a different version, make sure that the configuration you posted is in the correct .config file. Remember that there is no xpto.dll.config, a DLL loaded by an application always uses the config file of the running application.

如果您希望保留当前的解决方案,并使用不同的版本加载一个程序集,请确保您发布的配置在正确的.config文件中。记住没有xpto.dll。配置,由应用程序加载的DLL总是使用正在运行的应用程序的配置文件。

#14


5  

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

Works for me.... just put the version you are using in newVersion i.e(newVersion="7.0.0.0")

工作对我来说....将您正在使用的版本改为newVersion,即newVersion="7.0.0.0")。

#15


4  

We had the exact same issue that you mentioned. We're using nunit to run tests through CI, and we have nunit running a file called tests.nunit, which describe a list of test dll fixtures to run.

我们的问题和你提到的完全一样。我们使用nunit在CI中运行测试,并且我们有nunit运行一个名为test的文件。nunit,它描述了一个测试dll设备运行的列表。

Each test fixture had their own config file, but when run through the "tests.nunit" file the binding redirects seem to be ignored. The solution was to add the binding redirects to a new config file, "tests.config" that was beside the "tests.nunit" file.

每个测试夹具都有自己的配置文件,但是在运行“测试”时。nunit“文件绑定重定向似乎被忽略。解决方案是将绑定重定向到一个新的配置文件“测试”。配置“在测试旁边”。nunit”文件。

#16


4  

You should update the web.config file in the server. When nuget install NewtonSoft update this file including this code

你应该更新网络。配置文件在服务器。当nuget安装NewtonSoft更新这个文件时,包括这段代码。

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

#17


4  

You have 2 different versions of JSON.NET library in your solution. To solve this you should upgrade them to latest version. Follow these steps:

你有两个不同版本的JSON。解决方案中的网络库。要解决这个问题,您应该升级到最新版本。遵循以下步骤:

1-Open solution explorer 2-Right Click on solution name 3-Select Manage Nuget Packages for Solution 4-Select Updates from menu 5-Update JSON.NET package

1打开解决方案资源管理器2右键单击解决方案名称3-Select管理解决方案4从菜单5更新JSON的更新包。净包

This will resolve your issue.

这将解决你的问题。

link: 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=中性,PublicKeyToken=30ad4fe6b2a6aeed或它的一个依赖项。

#18


4  

Close solution.

关闭解决方案。

Open packages.config and *.csproj with text editor and delete any line have Newtonsoft.Json

打开包。配置和*。使用文本编辑器和删除任何行,都有Newtonsoft.Json。

Ex:
<Reference Include="Newtonsoft.Json,Version=9.0.0.0,Culture=neutral,PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net40\Newtonsoft.Json.dll</HintPath> <Private>True</Private> </Reference>

. \package \Newtonsoft.Json.9.0.1\lib\net40\Newtonsoft.Json。真正dll < / HintPath > <私人> < /私人> < /参考>

Or <package id="Newtonsoft.Json" version="9.0.1" targetFramework="net40" />

id = " Newtonsoft或 <包。json " version=" 9.0.1 " targetframework=" net40 ">

Open solution again and re-install Newtonsoft.Json by Install-Package Newtonsoft.Json

再次打开解决方案,重新安装Newtonsoft。Json的安装包Newtonsoft.Json

It work for me.

它为我工作。

#19


3  

I have got the same type of problem. And I also solved it just doing the following: Go to TOOLS > NuGet Package Manager and Select Package Manager Console. Finally, execute the following two commands :)

我有同样的问题。我还解决了下面的问题:使用工具> NuGet包管理器并选择包管理器控制台。最后,执行以下两个命令:)

  1. uninstall-package newtonsoft.json -force
  2. uninstall-package newtonsoft。json force
  3. install-package newtonsoft.json
  4. 安装包newtonsoft.json

#20


3  

In my case, the main project was still referencing an old version of Newtonsoft.Json which didn't exists in the project any more (shown by a yellow exclamation mark). Removing the reference solved the problem, no bindingRedirect was necessary.

在我的例子中,主要项目仍然引用了旧版本的Newtonsoft。在项目中不再存在的Json(用黄色感叹号表示)。删除引用解决了问题,没有绑定重定向是必要的。

#21


3  

I had the exact same problem with version 7.0.0.0, and the lib causing my problem was Microsoft.Rest.ClientRuntime which somehow was referring to the wrong version (6.0.0.0) of Newtonsoft.json, despite the right dependency management in nugget (the right version of newtonsoft.json (7.0.0.0) was installed).

我对7.0.0.0版本有同样的问题,而lib导致我的问题是Microsoft.Rest。ClientRuntime指的是Newtonsoft的错误版本(6.0.0.0)。json,尽管在金块(newtonsoft的正确版本)中有正确的依赖关系管理。json(那么)安装)。

I solved this by applying the redirection above from 6.0.0.0 to 7.0.0.0 (from Kadir Can) in the config file:

我通过在配置文件中从6.0.0.0到7.0.0.0(从Kadir Can)中应用重新定向来解决这个问题:

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

----> After a few days without changing anything it came up again with the same error. I installed version 6.0.0.0 n updated it to 7.0.0.0 it works fine now.

---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --我安装了版本6.0.0.0 n,更新到7.0.0.0,现在运行良好。

#22


2  

In my case, after downloading the assembly and adding the reference to the project, I solved this by 'unblocking' the DLL before adding the reference to the project.

在我的例子中,在下载了程序集并添加了对项目的引用之后,在添加对项目的引用之前,我通过“un阻塞”这个DLL解决了这个问题。

Using Windows explorer, browse to the DLL location, right-click on the DLL and then select 'properties'. You'll find an 'unblock' button on one of the tabs and then you can add the reference and the assembly will load correctly.

使用Windows资源管理器,浏览到DLL的位置,右键单击DLL,然后选择“属性”。您将在其中一个选项卡上找到一个“解锁”按钮,然后您可以添加引用,而程序集将正确加载。

#23


2  

I made the mistake of adding a NewtonSoft .dll file for .Net 4.5.

我错误地为。net 4.5添加了一个NewtonSoft .dll文件。

My main project was 4.5, but when I added an extra project to my solution, it strangely added it as a .Net 2.0 project... and when I attempted to use NewtonSoft's 4.5 dll with this, I got this "Newtonsoft.Json couldn't be found" error.

我的主要项目是4.5,但是当我在我的解决方案中添加一个额外的项目时,它奇怪地把它添加到。net 2.0项目中……当我尝试使用NewtonSoft的4.5 dll时,我得到了这个“NewtonSoft”。无法找到Json“错误”。

The solution (of course) was to change this new project from .Net 2.0 to 4.5.

解决方案(当然)是将这个新项目从。net 2.0改为4.5。

#24


2  

Nothing from above helped me, but what actually fixed it is the following:

上面没有任何东西能帮助我,但真正解决了问题的是:

  1. Remove all dependency bindings in app.config (from all app.config files in the solution)
  2. 在app.config中删除所有依赖项绑定(从解决方案中的所有app.config文件中删除)
  3. Execute the following command from "Package Manager Console"
  4. 从“Package Manager控制台”执行以下命令

Get-Project -All | Add-BindingRedirect

获得更多的项目——| Add-BindingRedirect

  1. Rebuild
  2. 重建

Reference: http://blog.myget.org/post/2014/11/27/Could-not-load-file-or-assembly-NuGet-Assembly-Redirects.aspx

参考:http://blog.myget.org/post/2014/11/27/Could-not-load-file-or-assembly-NuGet-Assembly-Redirects.aspx

#25


2  

Right click your project select manage Nuget packages, type newtonsoft in the search box and install the latest version. Then Run your App

右键单击项目选择管理Nuget包,在搜索框中键入newtonsoft并安装最新版本。然后运行你的应用

#26


2  

I was facing the same error and struggled with it for hours. I had a web API project which is using Newtonsoft.json and another UnitTest project for the web API project. The unit test project also needed the Newtonsoft.json reference. But on adding the link I was getting the above exception.

我面对着同样的错误,挣扎了好几个小时。我有一个使用Newtonsoft的web API项目。json和web API项目的另一个UnitTest项目。单元测试项目也需要Newtonsoft。json参考。但在添加链接时,我得到了上述异常。

I finally resolved it by adding the below code snippet in the app.config of the unit test project:

通过在单元测试项目的app.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>

#27


2  

Another insidious problem is that it appears that binding redirects can just silently fail if the element has an incorrect configuration on any other dependentAssembly elements.

另一个潜在的问题是,如果元素在任何其他依赖程序元素上有不正确的配置,那么绑定重定向就会导致静默失败。

Ensure that you only have one element under each element.

确保每个元素下只有一个元素。

In some instances, VS generates this:

在某些情况下,VS生成这个:

  <dependentAssembly>
    <assemblyIdentity ...
    <assemblyIdentity ...
  </dependentAssembly>

Instead of

而不是

  <dependentAssembly>
    <assemblyIdentity ...
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity ...
  </dependentAssembly>

Took me a long time to realise this was the problem!

我花了很长时间才意识到这是个问题!

#28


2  

If error disappears locally and still appears on server, the solution that works with me is to delete bin folder and packages.config and web.config and reupload these files

如果错误在本地消失,并且仍然出现在服务器上,那么与我一起工作的解决方案是删除bin文件夹和包。配置和网络。配置并重新上传这些文件。

#29


1  

The problem for me was a depreciated version of Newtonsoft.Json. Re-installing didn't help.

对我来说,问题是一个贬值的版本的Newtonsoft.Json。重装没有帮助。

In Visual Studio, go to Tools->Manage NuGet Packages. Select Updates. Search for Newtonsoft. Click Update to install the latest version.

在Visual Studio中,到Tools->管理NuGet包。选择更新。寻找Newtonsoft。单击Update安装最新版本。

#30


1  

Also, in a CI environment with NuGet restore, be sure that you don't have partial folders checked into source control. By default, when adding folders to source control, it will automatically exclude assemblies. Besides, this defeats the whole purpose of restoring nuget packages upon build. Either checking assemblies, or not checking in any packages folders will get a successful build, but the better practice is to not check nuget packages into source control.

另外,在带有NuGet恢复的CI环境中,请确保没有将部分文件夹检查到源代码控制中。默认情况下,当向源代码控制添加文件夹时,它将自动排除程序集。此外,这违背了在构建时恢复nuget包的全部目的。无论是检查程序集,还是在任何包文件夹中检查,都将获得成功的构建,但是更好的做法是不检查nuget包到源代码控制中。

#1


188  

In package manager console execute: Update-Package –reinstall Newtonsoft.Json.

在包管理器控制台执行:更新包-重新安装Newtonsoft.Json。

UPDATE

更新

I originally posted this as a comment but as @OwenBlacker suggested I'll just put it here:

我最初把这个作为评论,但是@OwenBlacker建议我把它写在这里:

If you still get an error after doing this, then what worked for me eventually is that I deleted Json.Net's <dependentAssembly> section from my .config file. 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.

如果您在执行完这个操作之后仍然有错误,那么最终对我有效的是我删除了Json。从我的.config文件中,Net的 部分。如果它不在那里,重新安装就会返回,显然你需要删除它。除非软件包本身有一个正常的解决方案,否则我恐怕这个手动步骤是必须的。

Note: Please read the comments below before doing this.

注意:在做这个之前请先阅读下面的评论。

As per René's comment below BE AWARE that the command posted in the answer will reinstall the package in every project in your solution. So if you use the Newtonsoft.Json package in several projects and maybe use different versions, just executing the above command might have unwanted consequences.

根据Rene的评论,请注意,在答案中发布的命令将在解决方案中的每个项目中重新安装包。如果你使用Newtonsoft。在多个项目中使用Json包,可能使用不同的版本,执行上述命令可能会产生不必要的后果。

#2


103  

To everyone having problems with Newtonsoft.Json v4.5 version try using this in web.config or app.config:

对每个人都有新的问题。Json v4.5版本尝试在web上使用它。配置或app.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-6.0.0.0" newVersion="6.0.0.0"/>
       </dependentAssembly>
    </assemblyBinding>
</runtime>

IMPORTANT: Check that the configuration tag of your config file has no namespace attribute (as suggested in https://*.com/a/12011221/150370). Otherwise, assemblyBinding tags will be ignored.

重要:检查配置文件的配置标记没有名称空间属性(如https://*.com/a/12011221/150370所建议的)。否则,将忽略汇编绑定标记。

#3


27  

The key point is referencing right version in your config file.

关键是在配置文件中引用正确的版本。

Steps;

步骤;

1- look at what is the version of your Newtonsoft.Json.dll in the project reference property what ever the version in your package folder (For example mine is 7.0.1 and the reference Version is 7.0.0.0)

1-看看你的Newtonsoft.Json版本是什么。项目引用属性中的dll文件(例如,我的包文件夹中的版本为7.0.1,参考版本为7.0.0.0)。

2- look at what the project expect from you in the exception (mine is 6.0.0.0)

2-看看这个项目对你的期望是什么(我的是6.0.0.0)

3- Add dependent assembly to your config file as it should be..

3-将附属程序集添加到配置文件中。

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

#4


23  

I had no luck with any of the solutions presented here (uninstalling, reinstalling, deleting references, creating bindingRedirects etc.) I had to go back to an old version of Newtonsoft. Version 5.0.6 had been working before, so I tried that one. I had to enter these two commands in the Package Console:

我在这里没有遇到任何的解决方案(卸载、重新安装、删除引用、创建bindingre等),我必须回到旧版本的Newtonsoft。版本5.0.6之前一直在工作,所以我尝试了这个。我必须在包控制台输入这两个命令:

uninstall-package newtonsoft.json -force

uninstall-package newtonsoft。json force

install-package newtonsoft.json -version "5.0.6"

安装包newtonsoft。json - version“5.0.6”

The -force option in the first command is required to force the uninstall. Dependencies with other assemblies prevent the uninstall without it.

第一个命令中的-force选项需要强制卸载。与其他程序集的依赖关系可以防止没有它的卸载。

#5


20  

I fixed the problem adding this binding redirect to my .config file:

我修正了将这个绑定重定向到.config文件的问题:

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

The error message complains about not finding version 4.5.0.0, the current version of Newtonsoft.Json is 6.0.0.0 so the redirect should go from 4.5 to 6.0, not viceversa

错误消息抱怨没有找到版本4.5.0.0版本,当前版本的Newtonsoft。Json是6.0.0.0,因此重定向应该从4.5到6.0,而不是viceversa。

#6


19  

I think you are pointing to the wrong target, change it to 4.5 instead of 6.0

我认为你指向错误的目标,将它改为4.5,而不是6.0。

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

This should work.

这应该工作。

#7


16  

I've spend couple of days trying to resolve this frustrating issue. I've tried pretty much everything that can be found on the web. Finally I found that this error could be caused (like in my case) by the different target .Net project versions (4.5 and 4.5.1) in one solution. The steps bellow fixed it for me:

我花了几天时间试图解决这个令人沮丧的问题。我已经试过了所有能在网上找到的东西。最后,我发现在一个解决方案中,不同的目标. net项目版本(4.5和4.5.1)可能会导致这个错误(就像我的例子一样)。下面的步骤为我解决了这个问题:

  1. Double check the .Net version of every project that's in your solution. Just right click on project and go to Properties.
  2. 仔细检查你的解决方案中每个项目的。net版本。右键点击项目,然后进入属性。

无法加载文件或程序集的Newtonsoft。Json、Version = 4.5.0.0文化=中立,都30 ad4fe6b2a6aeed

  1. If possible set the same .Net version for all projects. If not at least try to change the Startup project one (for me this was the one causing the issues).

    如果可能,为所有项目设置相同的。net版本。如果不是至少尝试改变启动项目一(对我来说这是导致问题的原因)。

  2. Remove all Newtonsoft.Json packs from the solution.

    删除所有Newtonsoft。来自解决方案的Json包。

    uninstall-package newtonsoft.json -force

    uninstall-package newtonsoft。json force

  3. Update all Newtonsoft.Json versions in all packages.config files, like so

    更新所有Newtonsoft。所有包中的Json版本。配置文件

    <package id="Newtonsoft.Json" version="7.0.1" targetFramework="net451" />

    <包id = " newtonsoft。json version=" 7.0.1 " targetframework=" net451 ">

  4. Reinstall Newtonsoft.Json from "Package Manager Console" with:

    重新安装Newtonsoft。来自“Package Manager Console”的Json:

    install-package newtonsoft.json

    安装包newtonsoft.json

  5. Rebuild the solution

    重建方案

(Optional) 7. If you changed the Startup project, return it again

(可选)7。如果您更改了启动项目,请再次返回。

#8


9  

Remove the Newtonsoft.Json assembly from the project reference and add it again. You probably deleted or replaced the dll by accident.

删除Newtonsoft。来自项目引用的Json程序集,并再次添加它。您可能会意外删除或替换dll。

#9


9  

I was writing a WebApi REST service client, so for me this error was caused by adding References to the System.Net.Http and System.Net.Http.Formatting assemblies manually via Add Reference, when I should have added the Microsoft.AspNet.WebApi.Client package via NuGet. See also this answer to another question.

我正在编写一个WebApi REST服务客户端,所以对于我来说,这个错误是由于添加了对System.Net的引用而引起的。Http和System.Net.Http。通过添加引用手动格式化程序集,当我应该添加Microsoft.AspNet.WebApi时。客户端通过NuGet包。再看另一个问题的答案。

#10


9  

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

Did the trick for me :)

给我的窍门:)

#11


7  

if you using multiple project in same solution and library of the one other check is all projects has same version of Newtonsoft.Json

如果您在同一解决方案中使用多个项目,而另一个检查的库中使用的是所有项目都具有相同版本的Newtonsoft.Json。

#12


6  

Normally adding the binding redirect should solve this problem, but it was not working for me. After a few hours of banging my head against the wall, I realized that there was an xmlns attribute causing problems in my web.config. After removing the xmlns attribute from the configuration node in Web.config, the binding redirects worked as expected.

通常添加绑定重定向应该可以解决这个问题,但是它对我不起作用。几小时后,我的头撞到墙上,我意识到在我的web.config中有一个xmlns属性导致问题。将xmlns属性从Web的配置节点中删除之后。配置,绑定重定向按预期工作。

http://www.davepaquette.com/archive/2014/10/02/could-not-load-file-or-assembly-newtonsoft-json-version4-5-0-0.aspx

http://www.davepaquette.com/archive/2014/10/02/could -不-负载-文件-或-装配- newtonsoft - json - version4 - 5 - 0 - 0. aspx

#13


5  

Deploy the correct version to the CI machine

将正确的版本部署到CI机器。

This is telling you that the assembly loader found a different version of the Newtonsoft.Json assembly, that does not match the reference you created in your project. To load the assembly correctly, you must either deploy the assembly side by side with your compiled code, or install the correct version of the assembly in the destination machine (i.e. in the GAC).

这告诉您,程序集加载器找到了不同版本的Newtonsoft。Json程序集与您在项目中创建的引用不匹配。要正确地加载程序集,您必须使用编译后的代码部署程序集,或者在目标机器(即GAC)中安装正确的程序集版本。

Alternative: make sure the configuration is in the correct file

选择:确保配置在正确的文件中。

If you want to keep the current solution, and load an assembly with a different version, make sure that the configuration you posted is in the correct .config file. Remember that there is no xpto.dll.config, a DLL loaded by an application always uses the config file of the running application.

如果您希望保留当前的解决方案,并使用不同的版本加载一个程序集,请确保您发布的配置在正确的.config文件中。记住没有xpto.dll。配置,由应用程序加载的DLL总是使用正在运行的应用程序的配置文件。

#14


5  

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

Works for me.... just put the version you are using in newVersion i.e(newVersion="7.0.0.0")

工作对我来说....将您正在使用的版本改为newVersion,即newVersion="7.0.0.0")。

#15


4  

We had the exact same issue that you mentioned. We're using nunit to run tests through CI, and we have nunit running a file called tests.nunit, which describe a list of test dll fixtures to run.

我们的问题和你提到的完全一样。我们使用nunit在CI中运行测试,并且我们有nunit运行一个名为test的文件。nunit,它描述了一个测试dll设备运行的列表。

Each test fixture had their own config file, but when run through the "tests.nunit" file the binding redirects seem to be ignored. The solution was to add the binding redirects to a new config file, "tests.config" that was beside the "tests.nunit" file.

每个测试夹具都有自己的配置文件,但是在运行“测试”时。nunit“文件绑定重定向似乎被忽略。解决方案是将绑定重定向到一个新的配置文件“测试”。配置“在测试旁边”。nunit”文件。

#16


4  

You should update the web.config file in the server. When nuget install NewtonSoft update this file including this code

你应该更新网络。配置文件在服务器。当nuget安装NewtonSoft更新这个文件时,包括这段代码。

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

#17


4  

You have 2 different versions of JSON.NET library in your solution. To solve this you should upgrade them to latest version. Follow these steps:

你有两个不同版本的JSON。解决方案中的网络库。要解决这个问题,您应该升级到最新版本。遵循以下步骤:

1-Open solution explorer 2-Right Click on solution name 3-Select Manage Nuget Packages for Solution 4-Select Updates from menu 5-Update JSON.NET package

1打开解决方案资源管理器2右键单击解决方案名称3-Select管理解决方案4从菜单5更新JSON的更新包。净包

This will resolve your issue.

这将解决你的问题。

link: 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=中性,PublicKeyToken=30ad4fe6b2a6aeed或它的一个依赖项。

#18


4  

Close solution.

关闭解决方案。

Open packages.config and *.csproj with text editor and delete any line have Newtonsoft.Json

打开包。配置和*。使用文本编辑器和删除任何行,都有Newtonsoft.Json。

Ex:
<Reference Include="Newtonsoft.Json,Version=9.0.0.0,Culture=neutral,PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net40\Newtonsoft.Json.dll</HintPath> <Private>True</Private> </Reference>

. \package \Newtonsoft.Json.9.0.1\lib\net40\Newtonsoft.Json。真正dll < / HintPath > <私人> < /私人> < /参考>

Or <package id="Newtonsoft.Json" version="9.0.1" targetFramework="net40" />

id = " Newtonsoft或 <包。json " version=" 9.0.1 " targetframework=" net40 ">

Open solution again and re-install Newtonsoft.Json by Install-Package Newtonsoft.Json

再次打开解决方案,重新安装Newtonsoft。Json的安装包Newtonsoft.Json

It work for me.

它为我工作。

#19


3  

I have got the same type of problem. And I also solved it just doing the following: Go to TOOLS > NuGet Package Manager and Select Package Manager Console. Finally, execute the following two commands :)

我有同样的问题。我还解决了下面的问题:使用工具> NuGet包管理器并选择包管理器控制台。最后,执行以下两个命令:)

  1. uninstall-package newtonsoft.json -force
  2. uninstall-package newtonsoft。json force
  3. install-package newtonsoft.json
  4. 安装包newtonsoft.json

#20


3  

In my case, the main project was still referencing an old version of Newtonsoft.Json which didn't exists in the project any more (shown by a yellow exclamation mark). Removing the reference solved the problem, no bindingRedirect was necessary.

在我的例子中,主要项目仍然引用了旧版本的Newtonsoft。在项目中不再存在的Json(用黄色感叹号表示)。删除引用解决了问题,没有绑定重定向是必要的。

#21


3  

I had the exact same problem with version 7.0.0.0, and the lib causing my problem was Microsoft.Rest.ClientRuntime which somehow was referring to the wrong version (6.0.0.0) of Newtonsoft.json, despite the right dependency management in nugget (the right version of newtonsoft.json (7.0.0.0) was installed).

我对7.0.0.0版本有同样的问题,而lib导致我的问题是Microsoft.Rest。ClientRuntime指的是Newtonsoft的错误版本(6.0.0.0)。json,尽管在金块(newtonsoft的正确版本)中有正确的依赖关系管理。json(那么)安装)。

I solved this by applying the redirection above from 6.0.0.0 to 7.0.0.0 (from Kadir Can) in the config file:

我通过在配置文件中从6.0.0.0到7.0.0.0(从Kadir Can)中应用重新定向来解决这个问题:

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

----> After a few days without changing anything it came up again with the same error. I installed version 6.0.0.0 n updated it to 7.0.0.0 it works fine now.

---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --我安装了版本6.0.0.0 n,更新到7.0.0.0,现在运行良好。

#22


2  

In my case, after downloading the assembly and adding the reference to the project, I solved this by 'unblocking' the DLL before adding the reference to the project.

在我的例子中,在下载了程序集并添加了对项目的引用之后,在添加对项目的引用之前,我通过“un阻塞”这个DLL解决了这个问题。

Using Windows explorer, browse to the DLL location, right-click on the DLL and then select 'properties'. You'll find an 'unblock' button on one of the tabs and then you can add the reference and the assembly will load correctly.

使用Windows资源管理器,浏览到DLL的位置,右键单击DLL,然后选择“属性”。您将在其中一个选项卡上找到一个“解锁”按钮,然后您可以添加引用,而程序集将正确加载。

#23


2  

I made the mistake of adding a NewtonSoft .dll file for .Net 4.5.

我错误地为。net 4.5添加了一个NewtonSoft .dll文件。

My main project was 4.5, but when I added an extra project to my solution, it strangely added it as a .Net 2.0 project... and when I attempted to use NewtonSoft's 4.5 dll with this, I got this "Newtonsoft.Json couldn't be found" error.

我的主要项目是4.5,但是当我在我的解决方案中添加一个额外的项目时,它奇怪地把它添加到。net 2.0项目中……当我尝试使用NewtonSoft的4.5 dll时,我得到了这个“NewtonSoft”。无法找到Json“错误”。

The solution (of course) was to change this new project from .Net 2.0 to 4.5.

解决方案(当然)是将这个新项目从。net 2.0改为4.5。

#24


2  

Nothing from above helped me, but what actually fixed it is the following:

上面没有任何东西能帮助我,但真正解决了问题的是:

  1. Remove all dependency bindings in app.config (from all app.config files in the solution)
  2. 在app.config中删除所有依赖项绑定(从解决方案中的所有app.config文件中删除)
  3. Execute the following command from "Package Manager Console"
  4. 从“Package Manager控制台”执行以下命令

Get-Project -All | Add-BindingRedirect

获得更多的项目——| Add-BindingRedirect

  1. Rebuild
  2. 重建

Reference: http://blog.myget.org/post/2014/11/27/Could-not-load-file-or-assembly-NuGet-Assembly-Redirects.aspx

参考:http://blog.myget.org/post/2014/11/27/Could-not-load-file-or-assembly-NuGet-Assembly-Redirects.aspx

#25


2  

Right click your project select manage Nuget packages, type newtonsoft in the search box and install the latest version. Then Run your App

右键单击项目选择管理Nuget包,在搜索框中键入newtonsoft并安装最新版本。然后运行你的应用

#26


2  

I was facing the same error and struggled with it for hours. I had a web API project which is using Newtonsoft.json and another UnitTest project for the web API project. The unit test project also needed the Newtonsoft.json reference. But on adding the link I was getting the above exception.

我面对着同样的错误,挣扎了好几个小时。我有一个使用Newtonsoft的web API项目。json和web API项目的另一个UnitTest项目。单元测试项目也需要Newtonsoft。json参考。但在添加链接时,我得到了上述异常。

I finally resolved it by adding the below code snippet in the app.config of the unit test project:

通过在单元测试项目的app.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>

#27


2  

Another insidious problem is that it appears that binding redirects can just silently fail if the element has an incorrect configuration on any other dependentAssembly elements.

另一个潜在的问题是,如果元素在任何其他依赖程序元素上有不正确的配置,那么绑定重定向就会导致静默失败。

Ensure that you only have one element under each element.

确保每个元素下只有一个元素。

In some instances, VS generates this:

在某些情况下,VS生成这个:

  <dependentAssembly>
    <assemblyIdentity ...
    <assemblyIdentity ...
  </dependentAssembly>

Instead of

而不是

  <dependentAssembly>
    <assemblyIdentity ...
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity ...
  </dependentAssembly>

Took me a long time to realise this was the problem!

我花了很长时间才意识到这是个问题!

#28


2  

If error disappears locally and still appears on server, the solution that works with me is to delete bin folder and packages.config and web.config and reupload these files

如果错误在本地消失,并且仍然出现在服务器上,那么与我一起工作的解决方案是删除bin文件夹和包。配置和网络。配置并重新上传这些文件。

#29


1  

The problem for me was a depreciated version of Newtonsoft.Json. Re-installing didn't help.

对我来说,问题是一个贬值的版本的Newtonsoft.Json。重装没有帮助。

In Visual Studio, go to Tools->Manage NuGet Packages. Select Updates. Search for Newtonsoft. Click Update to install the latest version.

在Visual Studio中,到Tools->管理NuGet包。选择更新。寻找Newtonsoft。单击Update安装最新版本。

#30


1  

Also, in a CI environment with NuGet restore, be sure that you don't have partial folders checked into source control. By default, when adding folders to source control, it will automatically exclude assemblies. Besides, this defeats the whole purpose of restoring nuget packages upon build. Either checking assemblies, or not checking in any packages folders will get a successful build, but the better practice is to not check nuget packages into source control.

另外,在带有NuGet恢复的CI环境中,请确保没有将部分文件夹检查到源代码控制中。默认情况下,当向源代码控制添加文件夹时,它将自动排除程序集。此外,这违背了在构建时恢复nuget包的全部目的。无论是检查程序集,还是在任何包文件夹中检查,都将获得成功的构建,但是更好的做法是不检查nuget包到源代码控制中。