Newtonsoft.Json Assembly Conflict

前端 未结 5 911
盖世英雄少女心
盖世英雄少女心 2020-12-01 05:38

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         


        
相关标签:
5条回答
  • 2020-12-01 05:47

    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:

    • Removed the existing System.Net.Http.Formatting from my References
    • Installed the Install-Package Microsoft.AspNet.WebApi.Client - which installed the required Http.Formatting.

    Once installed, the PostAsJsonAsync() worked as expected!

    Hope this saves someone time I've lost looking for a solution!

    0 讨论(0)
  • 2020-12-01 05:49

    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>
    
    0 讨论(0)
  • 2020-12-01 05:57

    +1 to zbarrier for his solution. Here's why it worked...

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


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


    1. 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: assembly-file interface Then, I double-clicked on the 1 [Neutral] icon which brought me to the assembly's information, seen here: assembly-file information

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


    Other notes in case anyone is still confused:

    • the <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.
    • the 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.
    • you can alter the oldVersion attribute to forward additional versions of the assembly. For example, I will probably edit mine to look more like zbarrier's answer.
    • the 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: sn command response As you can see, the Newtonsoft public key (30ad4fe6b2a6aeed) is located right there at the end.
    0 讨论(0)
  • 2020-12-01 05:58

    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)

    0 讨论(0)
  • 2020-12-01 06:10

    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>
    
    0 讨论(0)
提交回复
热议问题