I am playing with my mvc project.
-
I Nugeted a package called SocialAuth.Net into the project, which in turn uses Newtonsoft.Json.dll 4.0.0.0 (older) as one of its dependencies.
-
Then because I also needed Json.Net myself, I wanted a newer version, So I Nugeted Json.NET, which has a newer version 4.5.0.0 (newer).
Then problem happens. In my razor view “ViewBag.Title = ….” it has red underline saying:
Warning 1 c:\users\admin\documents\visual studio
2010\Projects\WebApp\WebApp\Views\Home\Index.cshtml: ASP.NET runtime
error: 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)
This is the Json part of my web.config:
<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>
So,
-
I went to References, checked and found Newtonsoft.Json was 4.0.0.0 (probably came with SocialAuth.Net), and I deleted it, and added the 4.5.0.0 reference I got from Nuget.
-
I went into WebApp/bin/debug/ folder and deleted everything, and then rebuilt the project.
However, once I rebuild the webapp, the Newton.Json 4.0.0.0 comes back into bin/debug/ regardless how I manually reference it to the new Nuget 4.5.0.0. and the same error comes back. I am stuck.
Do you have and idea how to deal with this dll issue? Thank you.
EDIT ———————————–
After a bit of thinking, I understand it is because first Json.Net (newer 4.5) is linked first, then the older one comes after it when building. So the older one overwrites the newer one.
I am not fimiliar with GAC installing, but know I could open that can of worms and install 2 versions there, which I don’t want to, because that means I have to do that to every machine I deploy the web app. Is there a way to play with the web.config and get around this?
You could try to install the SocialAuth.Net package with the
‑IgnoreDependenciesflag, then installing the dependencies manually and making sure that you only install the latest version of Json.Net library.Then at runtime the SocialAuth.Net package would respect the assembly redirect and load Json.Net (v4.5) instead of the old version.