简体   繁体   中英

ASP.NET Web APi 2

I am running an app built on ASP.NEt web api 2. I have installed the latest Newton.Json package. The app is running on Framework 4.5.1. However I have observed that whenever I want run the app I got this mysterious error stating that :

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)

I called it mysterious because I am referencing the right Newton.Json.

Please assit me.

Try going to references search for Newtonsoft.Json right click it, Then go to preferences and select copy local.

If you can't find Newtonsoft.Json in your references, right click on your project and select manage nuget package then search for it

I had the same issue with Newtonsoft.Json. You can see clearly that, in ur web.config, u have referenced version 6.0.0.0 but somewhere in ur code it requires 4.5.0.0. Hence there is version conflict.

It means ur Newtonsoft.Json.dll is of version 6.0.0.0 and ur referencing 4.5.0.0.
What u can try is,

1) Binding Redirect:

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

This redirects any request for 4.5 version to 6.0

2) Reinstall specific version : type in the 'projectName' which is trying to access 4.5 version

Get-Project projectName | Update-Package -reinstall Newtonsoft.Json -Version 6.0.1

Biding redirect had worked for me.

Happy coding!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM