I am setting up the API for my MVC-4 app and when I uncommented this line in Globals.asax.cs:
WebApiConfig.Register(GlobalConfiguration.Configuration);
I received this exception when I started my project back up:
An exception of type 'System.IO.FileLoadException' occurred in mscorlib.dll but was not handled in user code
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)
What should I do?
Update 1 (screenshots)
from what I can tell, JSON.Net looks like it is installed correctly.
Update 2
JSON.Net actually seems to work when the API routes are commented out in Globals.Asax. This doesn't throw any errors:
public ActionResult Index()
{
var foo = Newtonsoft.Json.JsonSerializer.Create();
return View();
}
Visual Studio only complains when this line is uncommented:
WebApiConfig.Register(GlobalConfiguration.Configuration);
This also occured to me today. Seems like there had been an update for json.net (now version 6.0.3), causing nuget to download the latest version after build. However references to old json.net libs might not get updated when there are depencies to other libs.
Solution: Manually open the manage nuget packages for solution window and uninstall old version(s) of json.net. Then take the latest version and install for all needed projects. That fixed the exact error you had for me...
-- edit --
Ok, so I found out that this solution worked for me locally, but remotely this did not solve my issues. Seems like there are some old dependencies from other libs hard referencing the 4.5.0.0 version of json.net. More topics on Stackoverflow.com provide the following solution.
Add this assembly binding redirect to your web.config file:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="1.0.0.0-4.5.0.0" newVersion="6.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Most probably Newtonsoft.Json DLL is not properly deployed.
Make sure you have the Newtonsoft.Json DLL in your (IIS / project) bin folder.
Alternatively, you can also install that DLL to GAC if you plan to use it across multiple projects.
It looks like that you don't have Newtonsoft.Json installed/referenced. Web API relies on this and won't work correctly until you resolve this dependency. You can install it via NuGet.
Simply delete your Newtonsoft.Json dll from bin folder then open package.config file and remove your Newtonsoft.Json entry from there then reinstalled your Newtonsoft.Json by command but don't installed newer version if you face this problem with newer version find old version command
like Install-Package Newtonsoft.Json -Version 6.0.8
now Install-Package Newtonsoft.Json -Version 7.0.1 is also aviable but i suggest to you installed 6.0.8 version its working
Related
I'm using Docusign in my (.netcore 3.1) project and I'm also using another nuget package which relies on minio.
Both seem to rely on Restsharp.
When I try to run my app I'm getting this error:
System.IO.FileLoadException: 'Could not load file or assembly 'RestSharp, Version=106.3.1.0, Culture=neutral, PublicKeyToken=598062e77f915f75'. The located assembly's manifest definition does not match the assembly reference. (0x80131040)'
Docusign Version: 4.4.1
This is a screenshot of the dependencies as viewed from visual studio:
I've tried adding this binding redirect in App.Config:
<configuration>
<runtime>
<dependentAssembly>
<assemblyIdentity name="RestSharp" publicKeyToken="598062e77f915f75" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-106.3.1.0" newVersion="106.10.1" />
</dependentAssembly>
</runtime>
</configuration>
This has had no impact whatsoever. Please can you help me. Any help very much appreciated! :)
Another version of the nuget fixes this problem. Please check latest version 4.4.1 has the fix.
The 4.4.1 version of the C# SDK depends on the specific version of RestSharp.dll, it must use version 106.3.1.0. A later version would not work.
This is a known issue and would probably only get fixed in version 4.5.0, and I don't know when that version would be released at this time.
The only workaround is to find restsharp.dll version 106.3.1.0 and add it as a reference or put it in the same folder so that it can be loaded (was going to say put it in the GAC but you're using .NET Core).
Revision: actually, if you want to build your own version of DocuSign.eSign.dll, you can go to https://github.com/docusign/docusign-csharp-client and build the code yourself.
I am getting this annoying error when running a webapi application. I am using newton JSON - version 9.01.
{"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)":"Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed"}
My project .netFramework is 4.0. To help solve this issue I had added a dependency assembly:
<assemblyIdentity name="Newtonsoft.Json"
publicKeyToken="30AD4FE6B2A6AEED" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
and my project package.config
<package id="Newtonsoft.Json" version="9.0.0.0" targetFramework="net40" />
Both are equal but I am still getting error. Why is this happening? This is strange because my error message shows different assembly version. I have already updated newtonjson 9.0.0 and am using it, but the error throws differently.
I have tried installing newtonjson 6.0.0, and then the package manager console is throwing an error:
Unable to find version '6.0.1' of package 'Newtonsoft.Json'.
Sometimes when downgrading to a lower version newton json, C# dependency is not supported already or installed like it shows.
What should I do? I am very new in installing nuget pakages . Your help is appreciated.
in Package Manager Console:
Update in project: in pakage manager console close the targeting project and reinstall Newton soft and do a rebuild
Update-Package Newtonsoft.Json -Reinstall
Does your solution have multiple projects that target different versions of Newtonsoft.Json? Right-click the solution and Manage NuGet packages. If Newtonsoft.Json shows up in the Consolidate tab, then update the projects to use the same version.
I am having problems running my web application.
The project setup is ASP.NET Core web application (.NET Framework). I don't seem to get any Build error. The project doesn't just run.
System.IO.FileLoadException: 'Could not load file or assembly 'Microsoft.Win32.Primitives, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)'
Try adding the System.Net.Http nuget package.
This happened to me after I had updated to Visual Studio 2017 15.4.5 and also updated a load of Nuget packages. I think part of the problem is also using .net framework 4.7.1 as well, which I installed last week...
The fix for me was to remove the dependent assembly from web.config, so just comment out or delete this section:
<dependentAssembly>
<assemblyIdentity name="Microsoft.Win32.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly>
In other for me to get it working i uninstalled the Microsoft.Win32.Primitives then installed the exact version which is 4.0. this worked fir me.
Note that there are higher versions but they did not work for me.
I accidently deleted my *.suo files and the problem fixed itself. Maybe it was an accident, or irrelevant but i just thought to share it.
If you are targeting .Net 4.7.1 project, I contend that a 4.7.1 versioned Primitives DLL is not available. Take a look at the properties in Nuget
I believe the Nuget expression would need a > not a = 4.6.
This feels like a hack, but it seemed to work. If you open Web.config, change this to 4.6
I am facing the error below
Could not load file or assembly 'Newtonsoft.Json, Version=7.0.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 could see the below in Web.config
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
</dependentAssembly>
So I changed it to
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.1.0" />
</dependentAssembly>
In packeges.config I could see the below entry
But still I am facing the same issue. Please help
A lot of things can go wrong and this error message tells you nothing.
But still I am facing the same issue.
Maybe the easiest way will be to try and reinstall the package.
Go to TOOLS > NuGet Package Manager and Select Package Manager Console. Execute the following two commands:
uninstall-package newtonsoft.json -force
install-package newtonsoft.json
If you still get an error after doing this, then what worked for me eventually is that I deleted Json.Net's section from my .config file. Reinstall brings it back if it's not there and apparently you need to delete it. Until there will be a normal solution in the package itself, I'm afraid this manual step is a must. In package manager console again execute:
Update-Package –reinstall Newtonsoft.Json
Also take a look at your .Net version of the projects in your solution.
This is the Microsoft solution with unloading the project.
I had the same issue. I followed ekostadinov's forced uninstall/reinstall steps, but needed to add one extra step:
I was upgrading my Solution to Framework 4.5.2. My old Web.Config file had a namespace in the configuration tag.
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
I updated to:
<configuration>
Then the bindingRedirect should work for whatever version of NewtonSoft you are using:
<runtime xmlns="">
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
</dependentAssembly>
</assemblyBinding>
This can happen if package.config contains 2 same packages name with a different version.
For Example,
<package id="System.Spatial" version="5.6.2" targetFramework="net45" />
<package id="System.Spatial" version="5.6.4" targetFramework="net45" />
Thank You.
I had the same issue and doing the uninstall and reinstall didn't help. At the time I was trying to install the most current version (10.0.3) of Newtonsoft.Json. I ended up installing the 7.0.1 version and then ran across another article that suggested copying that .dll to :\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE. Which I did.
Started the install REST API process again and then received a different error. When attempting to install Microsoft.Rest.ClientRuntime 2.3.2 it failed. For this, I just went into NuGet and had it install to the project in which I was installed the REST API.
Started the REST API install again and this time it installed.
Oh and if it helps anyone with searches, I was doing the Azure Immersion 02-API App tutorial using VS2015 on Windows Server 2012R2.
I had the same issue and I got the exception when I was trying to create MassTransit queues:
"Exception: System.TypeInitializationException: The type initializer for 'MassTransit.Serialization.JsonMessageSerializer' threw an exception. ---> System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=12.0.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)"
Solution that worked for me (after spending couple of days reverting several commits):
We had a windows service solution that has .Service project and
.XUnitTests project. Both of them were using a common nuget that has
dependency on Newtonsoft.Json.dll. There was no explicit reference to
Newtonsoft.Json nuget package in both projects (but we were using
'using Newtonsoft.Json;' namespace in our classes), so the common
nuget was using version 9 of Newtonsoft.Json by default.
As soon as I installed the Newtonsoft.Json nuget in both .Service and
.XUnitTests projects, the common nuget package started using the
latest v12 Newtonsoft and that fixed my issue.
Just posting it in here if it saves anyone their valuable time.
most of the time this error happens because of different assemblies are dependent on specific version of some other assembly.
the easiest fix is to update all packages that are dependent to Newtonsoft.Json using the nuget package manager.
it will automatically set all config files in your project.
I got the same error, and fixed it by doing a 'Clean' on my solution. I'm using Newtonsoft.Json in a UWP app.
Thanks #ekostadinov. I was able to get it working with the solution from #ekostadinov. In my case, the default Web MVC template had NewtonSoft JSON version 6. I had added a class library and to that I installed NewtonSoft JSON version 9 from Nuget package manager.
I tried removing the reference from my Web project, packages config and dependencies, but still I was getting error. Now, I was getting error message saying unable to find Newtonsoft JSON version 6. Initially I was getting error message saying unable to find Newtonsoft JSON version 9.
Then I followed #ekostadinov steps.
uninstall-package newtonsoft.json -force
install-package newtonsoft.json
I got a warning with respect to a dependency in the package manager console mentioning about a dependency with the version of Web.Grease dll. But anyways, it was successful.
Just to double check, I ran the last command mentioned in the above post
Update-Package –reinstall Newtonsoft.Json
It ran without any warnings as well.
Now, I am able to use version 9 in all my projects.
Well, in my case, there were multiple projects in the solution and each was using different version of NewtonSoft.json. I had to go ahead and change the version in each project's package.config to match with latest version(Well, it could be any version just that it should be same across the projects). Once all the package.config point to the same version, all I had to do was
Update-Package –reinstall Newtonsoft.Json
Now, watch out I also had to manually change the version on web.config assembly entry in one of the projects. but that did the job.
My be it is too late but hopefully, it might be useful for the people supporting old projects.
Add dependentAssembly tag and give the version number in oldVersion for which you are getting error.
In my case it was giving the error for version 6.0.0
Give the installed version value in newVersion as mentioned below:
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="10.0.0.0" />
</dependentAssembly>
My Windows service is in the same solution as a MVC project.
The MVC project uses a reference to SignalR Client which requires Newtonsoft.Json v6 +
the Windows service uses System.Net.Http.Formatting, which requires Newtonsoft.Json version 4.5.0.0.
I assumed this would not be a problem, as I could just use a binding redirect in my App.Config, however I get an error of
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)
my app.config has the following:
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
</dependentAssembly>
I added that myself, and it does not work, I have also tried uninstalling and re-installing Json.Net with the nuget package manager, to no avail
We faced same error and struggled to fix for few days. We finally we found this post on stack overflow Assembly reference cannot be resolved - dependentAssembly issue?
This made us realize to look into the version of System.Net.Http.Formatting being used and we found that our solution had been using multiple version of System.Net.Http.Formatting.dll and those each of them were referencing different version of Newtonsoft.Json.dll.
Removing references of older version of System.Net.Http.Formatting and adding references back, fixed the problem.
Hope that helps.
Does the assemblyBinding tag have proper xmlns schema? Check if the issue you are encountering is same as Assembly binding redirect does not work
#chintan123 actually pointed my in the right direction, turns out that despite the class library I was creating had a reference to both System.Net.Http.Formatting and also Newtonsoft.Json, only the former was being copied to the bin directory of the calling project that needed it.
Adding a reference to Newtonsoft.Json to the main calling project fixed the issue.