Newtonsoft.Json Assembly Conflict

I am using Netonsoft.Json in my project. It works fine until I start integrating Paypal SDK into my project. My code is as follows.

String AccessToken = new PayPal.OAuthTokenCredential("", "").GetAccessToken(); ---->>>> This Line Throwing An Error PayPal.Api.Payments.Address add = new PayPal.Api.Payments.Address(); add.city = TextBoxCity.Text; add.line1 = TextBoxAddress.Text; add.phone = TextBoxPhoneNumber.Text; add.postal_code = TextBoxZipcode.Text; add.state = TextBoxState.Text; PayPal.Api.Payments.CreditCard cc = new PayPal.Api.Payments.CreditCard(); cc.number = TextBoxCreditCardNumber.Text; cc.first_name = TextBoxFirstName.Text; cc.last_name = TextBoxLastName.Text; cc.expire_month = Convert.ToInt16(TextBoxExpiryMonth.Text); cc.expire_year = Convert.ToInt16(TextBoxExpiryYear.Text); cc.cvv2 = TextBoxCVVNumber.Text; cc.billing_address = add; cc.Create(AccessToken); 

and I get an error as below

  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 manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) 

I am searching the Internet and found some solution to modify the configuration file. SO I am changing my configuration file below

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

I also deal with assembly properties like Copy Local, Specific Version, but nothing helps me solve this problem. How can I resolve the build conflict?

+29
c # .net-assembly paypal-sandbox
Jul 21 '13 at 19:35
source share
5 answers

I had the same problem and solved it by updating Newtonsoft.Json to the latest version using

 Update-Package Newtonsoft.Json 

and then go to Web.config and add:

 <dependentAssembly> <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed"/> <bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="5.0.8"/> </dependentAssembly> 
+58
Dec 06 '13 at 2:16
source share

+1 for zbarrier to solve it. That's why it worked ...

+1 to zbarrier for his answer, which helped me solve my problem. Assembly references are the worst ... so I decided to post the steps I took, as well as some things that I learned, and hopefully this helps:




  • FAILED ATTEMPT: Insert 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> 

    ^^^^^ DOES NOT WORK




  1. SOLUTION: Navigate to ~/Bin/Newtonsoft.Json.dll and open 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 finally saw this: assembly-file interface Then I double clicked on the 1 [Neutral] icon, which led me to build, here: assembly-file information

    A line labeled Assembly Version is what you will need to enter in the newVersion attribute of the <bindingRedirect> . So I took the section I inserted (in the first step) and change "5.0.8" to "6.0.0.0". My new <runtime> section is as follows:

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

    ^^^^^ THIS WORKS !! At last...




Other notes in case someone is still confused:

  • the <runtime> tag is located in the <configuration></configuration> in web.config. The section shown above was inserted directly below the opening tag of my web.config <configuration> section.
  • The xmlns attribute is the corresponding XML namespace. This is used by assembly developers to avoid issues with conflicting labels. In this case, you should feel safe using xmlns="schemas-microsoft-com:asm.v1" listed above.
  • you can change the oldVersion attribute to redirect additional versions of the assembly. For example, I probably look more like a zbarrier answer .
  • publicKeyToken is another attribute that pretty much when it comes to Newtonsoft.Json. PublicKeyToken is just a shortened version of the public key - much like a book title - and in this case it doesn’t actually change. If you ever want to know the public key for the assembly, simply open the Developer Command Prompt , which can be found in the Start menu, then use the command line to go to the location of the assembly file (in this case ~\Bin\ ) and run the command sn -T assembly_file_name . So in this case the command was sn -T Newtonsoft.Json.dll . You should get an answer like this: sn command response As you can see, the Newtonsoft key publication ( 30ad4fe6b2a6aeed ) is right at the end.
+30
Feb 19 '15 at 17:04
source share

I ran into the same problem for building version 6.0.1. I inserted the following lines in 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> 

Then I deleted the link to the Newtonsoft.Json project and deleted the link to Newtonsoft.Json in the packages.config file.

I opened Nuget Manager and reinstalled Newtonsoft.Json.

The installation 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> 
+22
Feb 07 '14 at 23:36
source share

At first, I thought that my case was the same old assembly reference ... deleted, reinstalled, force installed, rebuilt, added a redirect assembly ... etc.

Nothing worked until I found out that another assembly was causing a problem.

In my case, my code failed when I called the HttpClient.PostAsJsonAsync (requestURI, T) method. The error in the Assembly Reference threw me away, because my solution had several projects, and some projects used the old version ... ended up spending a lot of time, bye ...

My decision:

  • Removed existing System.Net.Http.Formatting from my links
  • Installed the installation package Microsoft.AspNet.WebApi.Client - which installed the necessary Http.Formatting.

After installing PostAsJsonAsync () worked as expected!

Hope this saves me from the ones I lost looking for a solution!

+2
Sep 29 '15 at 16:22
source share

I had the same problem: I installed Newtonsoft.Json v9.0.1, sandcastle stops the assembly displaying the same error, but with a version difference: "Could not load the file or assembly" Newtonsoft.Json, Version = 6.0.0.0, "

what worked: find / create a project using newtonsoft.json with the version that SandCastle is requesting, add the file "Newtonsoft.Json.dll" as a link to the SC project, which will then be created. (you can find the dll in the bin folder of the project)

0
Jul 19 '16 at 11:13
source share



All Articles