After running a clean solution and rebuild, my MVC 4 Web API project stops working. It's can't find Newtonsoft.Json.
I know that MS is using this as the default JSON serializer now - but its not in the references list for the project, and I can't add it from NuGet as it says it's already installed.
Does anyone have any idea here as to what could be going wrong?
Full stack trace:
[FileNotFoundException: 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 specified.]
MvcWebRole1.WebApiApplication.Application_Error() in d:\Data\Source Controlled Projects\georace\georace\Server\GeoRaceServer\MvcWebRole1\Global.asax.cs:70[HttpException (0x80004005): 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 specified.]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +12838633
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +175
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +304
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +404
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +475[HttpException (0x80004005): 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 specified.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12851296 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12679949
What caused my problem with Newtonsoft.json was slightly different. I had developed a Windows app built against .Net 4.5. I later found out that the customer's environment only supported .Net 4.0. I had copied the solution to a new area to preserve the .Net 4.5 work and changed the Solution Properties to Microsoft.Net 4.0. I got the error that Newtonsoft.json could not be found and was I missing a reference.
I followed the procedures stated above for removing the packages.config; removing Newtonsoft.json; ensuring that Newtonsoft.json was removed from the \packages directory; then reinstalling Newtonsoft.json from NuGet. I was able to compile and run the application with .Net 4.0
Prior to this the packages.config file showed that the version of .Net that Newtonsoft.json targeted was .Net 4.5. Removing and adding the Newtonsoft.json now has the target as .Net 4.0.
Check to see if you had an 'old style' (pre nuget) reference to JSON.NET pointing to an out of date local copy embedded in your project.
I had an old
Reference\Lib\JSON.NET
which was in my reference path and getting priority.Check that the JSON.NET properties page is pointing to the expected Nuget package version.
I had this problem on a Team Server build which deployed live. I had to fix my original solution and do a clean build to make sure the old
Reference\Lib\
DLL wasn't being picked up.I was having the same FileNotFoundException and it turns out that I already have the reference to Newtonsoft.Json on my project, BUT the "Copy Local" property wasn't set to TRUE. Just set it to TRUE so the dll gets copied to the output directory if this is your case too.
You could try to install the SocialAuth.Net package with the ‑IgnoreDependencies flag, 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.
I had the same problem in VS2012 express, and I managed to install it from
There I found and installed Newtonsoft Json. It wasn't installed in none of the projects from solution by then.
I combined a couple of the options the other SO contributors stated, plus a new one.
First, It turns out that Nuget 2.1 had some issues, and this issue was logged in a bug, and was fixed in 2.2.2. See here: https://nuget.codeplex.com/workitem/3050
So, I did the following steps: