2

In my MVC 4 Web API project stops working. It's can't find Newtonsoft.Json. After running this code :

 Dim response As HttpResponseMessage = MyHttpClient.PostAsJsonAsync("Api/Test", MyObject).Result

I get message error :

An unhandled exception of type 'System.IO.FileLoadException' occurred in System.Net.Http.Formatting.dll

Additional information: 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 know that MS is using this as the default JSON serializer now - and it’s referenced. I tried to update Newtonsoft.Json from NuGet but I can't find it; I find "Json.Net". So I used package manager console to reinstall

Update-Package Newtonsoft.Json –Reinstall

But still doesn’t work. Does anyone have any idea why is this going wrong?

2 Answers 2

2

It seems that you are using some outdated library that depends on an old version of JSON.NET. You could try to install the specific version of it:

Update-Package Newtonsoft.Json -Version 4.5.11

If this fails telling you that some other package requires a newer version of JSON.NET then you will need to resolve this conflict by upgrading the outdated library that you are using and which depends on JSON.NET 4.5

Sign up to request clarification or add additional context in comments.

5 Comments

i get Parameter set cannot be resolved using the specified named parameters. At line:1 char:15 + Update-Package <<<< Newtonsoft.Json -Reinstall -Version 4.5.11 + CategoryInfo : InvalidArgument: (:) [Update-Package], ParameterBindingException + FullyQualifiedErrorId : AmbiguousParameterSet,NuGet.PowerShell.Commands.UpdatePackageCommand
Sorry, I made a typo, just get rid of the -Reinstall parameter - I have updated my answer.
Update-Package : Updating 'Newtonsoft.Json 6.0.8' to 'Newtonsoft.Json 4.5.11' failed. Unable to find versions of 'WebGrease, Microsoft.AspNet.WebApi.Client' that are compatible wit h 'Newtonsoft.Json 4.5.11'. At line:1 char:15 + Update-Package <<<< Newtonsoft.Json -Version 4.5.11 + CategoryInfo : NotSpecified: (:) [Update-Package], Exception + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.UpdatePackageCommand
So yeah, as I said you will need to update the old package that you are using in your project which depends on this legacy version of JSON.NET
I removed the JSON.NET package and install old version that using in my project .... Thank you ...
2

Try to add this section in your web.config file inside <runtime><assemblyBinding>:

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

1 Comment

There exist in my web.config

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.