I use Netonsoft.Json in my project. It works fine until I start integrating Paypal SDK in my Project. My code is as below.
String AccessToken =
ne
At first , i thought my case was the same old assembly reference ... did the uninstall, reinstall, force install, rebuild, add redirect assembly ...etc
Nothing worked until, I found out that another assembly was causing the problem.
In my case, my code was failing when I called the HttpClient.PostAsJsonAsync(requestURI, T ) method. The error about Assembly Reference threw me off since my Solution has multiple projects and in which some of the projects used an old version... ended wasting a lot of time until...
My solution:
Once installed, the PostAsJsonAsync() worked as expected!
Hope this saves someone time I've lost looking for a solution!
I just had the same problem and I solved it by updating the Newtonsoft.Json to the latest version using
Update-Package Newtonsoft.Json
and then going to Web.config and adding:
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed"/>
<bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="5.0.8"/>
</dependentAssembly>
+1 to zbarrier for his answer which helped me solve my issue. Assembly reference issues are the worst...so I thought I would post the steps I took, as well as some things I learned, and hopefully it helps:
FAILED ATTEMPT: Pasted the following lines into my web.config
:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed"/>
<bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="5.0.8"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
^^^^^ DID NOT WORK
SOLUTION: Navigated to ~/Bin/Newtonsoft.Json.dll
, and opened the file in
Visual Studio. By default, the interface for the file displays a folder
named after the assembly--I double clicked it to expand, and
eventually saw this: Then, I double-clicked
on the 1 [Neutral]
icon which brought me to the assembly's information,
seen here:
The line that says Assembly Version
is what you'll need to enter
into the newVersion
attribute of the <bindingRedirect>
tag. So I took
the section I pasted (in step one) and change the "5.0.8" to
"6.0.0.0". My new <runtime>
section looks like this:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed"/>
<bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="6.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
^^^^^ IT WORKED!! Finally...
<runtime>
tag goes within the <configuration></configuration>
tag in the
web.config. The section I show above was pasted directly below the opening tag of my web.config's <configuration>
section.xmlns
attribute represents the corresponding XML namespace.
This is used by the developers of the assembly to avoid issues with
conflicting tags. In this case you should feel safe using the
xmlns="schemas-microsoft-com:asm.v1"
listed above.oldVersion
attribute to forward additional
versions of the assembly. For example, I will probably edit mine to
look more like zbarrier's answer.publicKeyToken
is another attribute that pretty much stays the
same when it comes to Newtonsoft.Json. The publicKeyToken is just a
shortened version of the public key--much like a title is to a
book--and in this case doesn't really change. If you ever want to
know the public key to an assembly, just open the Developer Command
Prompt
which can be found in the start menu, then use the command prompt to navigate to the
location of the assembly file (in this case ~\Bin\
), and run the
sn -T assembly_file_name command. So in this case, the command was sn -T Newtonsoft.Json.dll. You should get a response like
this: As you can see, the Newtonsoft public
key (30ad4fe6b2a6aeed) is located right there at the end.I faced the same problem, I have installed Newtonsoft.Json v9.0.1 , sandcastle stops the build displaying the same error but with version difference: "Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0,"
what worked: find/create a project with newtonsoft.json with the version SandCastle is asking for, add the file "Newtonsoft.Json.dll" as a reference to the SC project then build. (you can find the dll in the bin folder of the project)
I ran into the same problem for assembly version 6.0.1. I pasted the following lines into the web.config as directed by Harold:
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed"/>
<bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="5.0.8"/>
</dependentAssembly>
I then removed the project reference to Newtonsoft.Json and deleted the reference to Newtonsoft.Json in the packages.config file.
I opened the Nuget Manager and reinstalled Newtonsoft.Json.
The install changed the web.config settings to the following and everything worked fine:
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>