TARKUS
TARKUS

Reputation: 2200

type or namespace name 'Newtonsoft' could not be found

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.

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?

Upvotes: 20

Views: 110457

Answers (6)

Rineesh Ch
Rineesh Ch

Reputation: 11

Make sure you are installing the correct version of Newtonsoft.Json NuGet package.

this worked for me..!

Upvotes: 1

Okechukwu Ezekiel
Okechukwu Ezekiel

Reputation: 101

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

Upvotes: 4

Taurus999able
Taurus999able

Reputation: 91

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.

Upvotes: 8

Gonzalo.-
Gonzalo.-

Reputation: 12672

When you copy files of a solutions, some references can be "lost". Try to delete the reference and add it again, after you copied the files and open in the other machine.

Also, take a look at this question: reference dll not copying to bin with deployment project causing error

Upvotes: 4

k3yz101
k3yz101

Reputation: 529

Another possible reason for this issue is if the project is using NuGet packages and they haven't been restored (downloaded) yet.

They may need to be restored in Visual Studio or you can use the nuget.exe command-line executable to restore the packages.

https://docs.nuget.org/consume/package-restore

Upvotes: 1

TARKUS
TARKUS

Reputation: 2200

Thanks for the pointer and the link. After a struggle I got it to work. What finally happened was my friend, an expert in .NET Skyped me and talked me through the proper way of deploying my project to the destination server. I didn't understand that there is a separate folder where your Build goes. I made a "Build Deployment Package" as a zip file. Then I unzipped it on my hard drive, and dropped it into a clean folder on the web server (actually, I uploaded it to the root directory), and voila, it worked.

Upvotes: 2

Related Questions