type or namespace name 'Newtonsoft' could not be found

Viewed 68921

I've looked this question up, but I don't see too many answers, and obviously none have been helpful or I wouldn't be asking. I am a .NET neophyte.

My local environment is Win7, Microsoft Virtual Web Developer 2010 Express. I added the NewtonSoft.Json as a custom component library.

  • I built a simple "HelloWorld" web service, using Newtonsoft.Json custom components.

  • When I do a build on my local machine (Visual Web Developer 2010 Express) it works great. I actually get a valid JSONP output, not XML.

  • When I FTP my files to the remote web server, my web service does not work. I get this:

Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0246: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)

Source Error:

Line 7: using System.Web.Services.Protocols;

Line 8: using System.Web.Script.Services;

Line 9: using Newtonsoft.Json;

Line 10:

Line 11: namespace System.Web.Script.Services.CS

I have tried everything from copying my entire project folder to the remote folder, then deleting everything and just copying my asmx and web.config file, and I still get the error. I copied the bin folder, with the Newtonsoft.Json.dll to the remote server, then tried copying it into the root folder, and to no avail.

Is there some operation that must be performed on the remote server to enable it to use Newtonsoft.Json.dll?

5 Answers

First step is try to rebuild your project. If it doesn't help: find 'Newtonsoft' in 'Nuget package Manager' and uninstall it. If it have a references => put checkboxes (Remove dependencies, Force uninstall) and in dropdowns (Dependency behavior => Ignore dependencies, File conflict action => Ignore All)

Install 'Newtonsoft' again.

The best way to fix this is to "Clean Solution"

In the solutions explorer in Visual studio, Right-click on the solution and Select "Clean Solution"

Clean Solution - deletes all compiled files (all dll’s and exe’s ).
Build Solution - compiles code files (dll and exe) that have changed.
Rebuild Solution - Deletes all compiled files and Compiles them again regardless of whether or not the code has changed.

Reference: https://bitwizards.com/thought-leadership/blog/2014/august-2014/visual-studio-why-clean-build-rebuild

Related