Visual Studio 2012 Web API project won't run - can't find Newtonsoft.Json

后端 未结 13 1360
余生分开走
余生分开走 2020-12-02 09:56

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 JS

相关标签:
13条回答
  • 2020-12-02 10:20

    I tested everything that was said here and nothing worked. In my case I had a path folder like this.

    • #Projects/Web/App/...

    The # the cause of my problem. I removed the # and worked fine.

    0 讨论(0)
  • 2020-12-02 10:26

    For me the only thing that fixed this error was to add the missing section to my web.config file, which I got from this answer here: https://stackoverflow.com/a/20414714/940783

    Here is what I needed 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>
    
    0 讨论(0)
  • 2020-12-02 10:29

    Ok - found a work around myself, posting in case someone else gets caned by this MS bug. The problem is that you can't add a NuGet reference as it's already included in the packages by default. So...

    1. Open up packages.config
    2. Delete the Newtonsoft.Json entry.
    3. Save and Build
    4. Re-add Newtonsoft.Json from NuGet.
    5. Build and run
    0 讨论(0)
  • 2020-12-02 10:29

    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:

    1. Updated Nuget version to 2.2.2 as per the link
    2. Removed all references to Json in my project by uninstalling from NUget (right click project and find package, and uninstall (Even this didn't do it)
    3. Physically deleted the Package files from the computer. I found package files here: //projectdir/packages/Newtonsoft.JSON
    4. Deleted the packages.config file from the physical directory (//projectname/packages.config)
    5. Once this was all completed, I added Newtonsoft again via Nuget, then did a rebuild, and it worked.
    0 讨论(0)
  • 2020-12-02 10:31

    For any package already installed by NuGet that you want to re-install just type the following command in 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
    
    0 讨论(0)
  • 2020-12-02 10:35

    I had the same problem (in VS2012). No answer helped me. Finally I solved it by this:

    1) Go to TOOLS -> EXTENSIONS AND UPDATES here update (or install) "NuGet Package Manager" next go to "Online" and install "Quick add NuGet" and "NuGet References"

    2) after insttal all in 1) in your project right click to "References" and choose "Manage Nuget Packages" in "Installed packages" find Json.NET. Click Uninstall - you cannot do this now, but it show you what you must uninstall first (some ASP Web Api client). So uninstall all of these and try uninstall "Json.NET" again. Now go to "Online" and install "Json.NET", "ASP.NET WEB API Client Libraries" and "ASP.NET WEB API Client OData".

    3) in Global.asax delete row "WebApiConfig.Register(GlobalConfiguration.Configuration);"

    build solution and all shoud be ok.. I hope this can help someone :) gl

    0 讨论(0)
提交回复
热议问题