Visual Studio 2012 Web API project does not start - Cannot find Newtonsoft.Json

After starting a clean solution and recovering, my MVC 4 Web API project stops working. He cannot find Newtonsoft.Json.

I know that MS uses this as the default JSON serializer, but it is not in the list of links for the project, and I cannot add it from NuGet since it says that it is already installed.

Does anyone know here what could be 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 specified file.]
MvcWebRole1.WebApiApplication.Application_Error () in d: \ Data \ Source Managed 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 specified file.]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode (HttpContext context, HttpApplication application) +12838633
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS (IntPtr appContext, HttpContext context, MethodInfo [] +175 handlers
System.Web.HttpApplication.InitSpecial (HttpApplicationState state, MethodInfo [] handlers, IntPtr appContext, HttpContext context) +304
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance (IntPtr application context, 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 specified file.]
System.Web.HttpRuntime.FirstRequestInit (HttpContext context) +12851296 System.Web.HttpRuntime.EnsureFirstRequestInit (HttpContext context) +159 System.Web.HttpRuntime.ProcessRequestNotificationPrivate (IIS7W67erontp12 + context)

+59
c # asp.net-web-api visual-studio-2012
Aug 19 '12 at 15:09
source share
13 answers

Good - found a job around him, posting in case someone else gets infected with this MS error. The problem is that you cannot add a NuGet link as it is already included in the packages by default. So that...

  • Open .config package
  • Delete the Newtonsoft.Json entry.
  • Save and build
  • Re-add Newtonsoft.Json from NuGet.
  • Assembly and launch
+81
Aug 19 '12 at 15:35
source share

For any package already installed by NuGet that you want to reinstall, enter the following command in the Package Manager Console :

Update in any project:

Update-Package Newtonsoft.Json -Reinstall 

Update in a specific project

 Update-Package Newtonsoft.Json -Reinstall -Project My.App 
+47
Jan 16 '13 at 20:16
source share

The only thing that fixed this error was to add the missing section to my web.config file, which I received from this answer here: https://stackoverflow.com/a/212618/

Here is what I need to add:

  <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> 
+35
Feb 06 '14 at 20:35
source share

I combined a couple of options that other SO members were talking about, plus a new one.

Firstly, it turns out that Nuget 2.1 has some problems, and this problem was recorded in a bug and was fixed in 2.2.2. See here: https://nuget.codeplex.com/workitem/3050

So, I took the following steps:

  • Updated version of Nuget to version 2.2.2 at the link
  • Removed all Json links in my project by deleting from NUget (right-click the project and find the package and delete (Even this was not done)
  • Physically deleted package files from a computer. I found package files here: //projectdir/packages/Newtonsoft.JSON
  • Removed packages.config file from the physical directory (//projectname/packages.config)
  • Once all this was completed, I added Newtonsoft again via Nuget, then recreated and it worked.
+4
Mar 11 '13 at 1:00
source share

I had the same problem (in VS2012). No answer helped me. Finally, I solved it as follows:

1) Go to TOOLS → EXTENSIONS AND UPDATES here to update (or install) the “NuGet Package Manager” then go to the “Internet” and install “Quick Add NuGet” and “Links to NuGet”

2) after everything in 1) in your project, right-click "Links" and select "Manage Nuget Packages", in "Installed Packages" find Json.NET. Click “Uninstall” - you cannot do it now, but it will show you what you should uninstall first (some ASP Web Api client). Therefore, delete all these files and try deleting "Json.NET" again. Now go to the Internet and install Json.NET, ASP.NET WEB API Client Libraries, and ASP.NET Web Interface Client OData.

3) in the Global.asax removal line "WebApiConfig.Register (GlobalConfiguration.Configuration);"

build a solution and everything will be ok .. I hope this can help someone :) gl

+4
Mar 04 '14 at 13:44
source share

Check if you had a "pre nuget" link to JSON.NET pointing to an outdated local copy embedded in your project.

I had an old Reference\Lib\JSON.NET that was in my reference path and got priority.

Make sure the JSON.NET properties page points to the expected version of the Nuget package.

I had a problem with the Team Server build, which was deployed live. I had to fix my original solution and make a clean build to make sure the old Reference\Lib\ DLL was not raised.

+3
Nov 15
source share

I had the same FileNotFoundException, and it turned out that I already have a link to Newtonsoft.Json in my project, BUT the Copy Local property was not set to TRUE. Just set it to TRUE, so that the dll is copied to the output directory, if that is also your case.

+1
Jan 24 '14 at 15:15
source share

I checked everything that was said here and nothing worked. In my case, I had a path folder similar to this one.

  • # Projects / Web / App / ...

# cause of my problem. I deleted # and worked fine.

+1
Feb 20 '14 at 18:31
source share

What caused my problem with Newtonsoft.json was slightly different. I developed a Windows application built against .NET 4.5. Later I found out that the client environment only supports .Net 4.0. I copied the solution to a new area to keep .Net 4.5 working and changed the Solution Properties to Microsoft.Net 4.0. I got an error that Newtonsoft.json could not find, and I was missing a link.

I followed the procedures above to remove packages.config; uninstall Newtonsoft.json; that Newtonsoft.json has been removed from the \ packages directory; then reinstall 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 .Net version that Newtonsoft.json was aiming for was .Net 4.5. Removing and adding Newtonsoft.json now has a goal as .Net 4.0.

+1
Mar 16 '14 at 14:13
source share

I did this by mistake, and he sorted it perfectly.

Having launched the new VS 2012 project, I used NuGet to install Newtonsoft.JSON, since the mentioned version 4.5.6 was already installed, and I was impressed to see that it was removed and installed 4.5.10.

Sweet.

0
Oct 26
source share

In my case, I checked a colleague's project, which somehow changed my Newtonsoft.Json recommendation, so I had to delete it. Right click on the project -> Manage NuGet Packages. On the left side, click “Installed packages”, then select Json.NET and uninstall it. In my case, I also had to remove other dependent packages (Microsoft ASP.Net Web API and others). Select "Internet" on the left side and find Json.Net, reinstall it.

0
Dec 18 '12 at 20:40
source share

You can try installing the SocialAuth.Net package with the -IgnoreDependencies flag, and then manually install the dependencies and make sure that you install only the latest version of the Json.Net library.

Then at run time, the SocialAuth.Net package will respect assembly redirection and load Json.Net (v4.5) instead of the old version.

0
Feb 18 '14 at
source share

I had the same problem in VS2012 express and I managed to install it from

TOOLS → NuGet Package Manager → NuGet Package Management for Solution

There I found and installed Newtonsoft Json. It was not installed in any of the projects from the solution.

0
Jul 16 '16 at 12:09
source share



All Articles