The Web API project will not start when it is deployed. Failed to load file or assembly. Newtonsoft.Json, Version = 4.5.0.0

I keep getting this error when deploying my MVC 5 WEB API project:

Could not load file or assembly 'Newtonsoft.Json, Version = 4.5.0.0, Culture = neutral, PublicKeyToken = 30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file.

I followed this and reinstalled the NuGet package "Updating the Newtonsoft.Json -Reinstall Package", but it did not work.

Does anyone know here what could be wrong?

+6
source share
5 answers

Check the link to the Newtonsoft.json DLL and make sure that it does not automatically select a version outside the package folder in your solution.

My VS 2013 continued to find other copies in various folders /program files (x86)/... He ignored even explicitly adding the package version DLL to the project. I had to dig deeper to find out why this is happening ...

Research

I opened the .csproj project .csproj in text editing mode and searched for all the links to Newtonsoft.Json.

It turned out that I had not one but two links to the DLL in my csproj file (I did not know that this was possible). One of them referred to the older Newtonsoft.json 5.0.6 (the current one was 5.0.8).

Decision

Instead of manually deleting one of them, I added this missing element to the second inclusion of the DLL. I also changed the version number to 5.0.8:

  <Private>True</Private> 

now it looks like this:

 <Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <HintPath>..\..\CsQueryTest\packages\Newtonsoft.Json.5.0.8\lib\net45\Newtonsoft.Json.dll</HintPath> <Private>True</Private> </Reference> 

Private is a parameter that defines Copy Local for a DLL reference. Then he turned the DLL back on!

I will figure out what to remove from the csproj file, but for now this may lead to you if you have this problem. It seems like the reason could be a past NUGET update.

+6
source

Have you tried redirecting the assembly to your web configuration to make sure your application is looking for the correct version:

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

Manage Nuget packages for the whole solution, not just the project. You should see several versions of Newtonsoft.Json. Select the lowest version and select Manage. Uncheck all selected check boxes and confirm. After it has been successfully removed, repeat the process for any other smaller versions. When all that you have left is one, the latest version of the package, click "Manage" on this and check all the projects in which they are missing. Once this is done, you will be fine.

+2
source

The latest version of Newtonsoft JSON is 5.0.8, which is most likely due to your reinstallation through NuGet.

If, when you right-click and look at the properties of the Newtonsoft JSON DLL link, and it says 5.0.8, you can just set the specific version to False, and your current code should work.

0
source

The project template in VS2013 has this very annoying habit, it refers to Newtonsoft.Json as the nuget HOWEVER package under the link properties β€œCopy local”, it is marked as False .

Check "Copy local" to True

Essentially create a new project -> deployment does not work without this setting.

Side Note: Updating Newtonsoft.Json will change Copy Local to True.

0
source

Source: https://habr.com/ru/post/959403/


All Articles