.net 找不到类型或命名空间名称“Newtonsoft”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11697479/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 16:33:18  来源:igfitidea点击:

type or namespace name 'Newtonsoft' could not be found

.netjson.net

提问by TARKUS

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.

我查过这个问题,但我没有看到太多答案,显然没有一个有帮助,否则我不会问。我是 .NET 新手。

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

我的本地环境是Win7,Microsoft Virtual Web Developer 2010 Express。我添加了 NewtonSoft.Json 作为自定义组件库。

  • 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:

  • 我使用 Newtonsoft.Json 自定义组件构建了一个简单的“HelloWorld”Web 服务。

  • 当我在本地机器(Visual Web Developer 2010 Express)上进行构建时,效果很好。我实际上得到了一个有效的 JSONP 输出,而不是 XML。

  • 当我将文件通过 FTP 传输到远程 Web 服务器时,我的 Web 服务不工作。我明白了:

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

编译错误说明:在编译服务此请求所需的资源期间发生错误。请查看以下特定错误详细信息并适当修改您的源代码。

编译器错误消息:CS0246:找不到类型或命名空间名称“Newtonsoft”(您是否缺少 using 指令或程序集引用?)

源错误:

第 7 行:使用 System.Web.Services.Protocols;

第 8 行:使用 System.Web.Script.Services;

第 9 行:使用 Newtonsoft.Json;

第 10 行:

第 11 行:命名空间 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.

我已经尝试了所有方法,从将整个项目文件夹复制到远程文件夹,然后删除所有内容并仅复制我的 asmx 和 web.config 文件,但仍然出现错误。我将带有 Newtonsoft.Json.dll 的 bin 文件夹复制到远程服务器,然后尝试将其复制到根文件夹中,但无济于事。

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

是否必须在远程服务器上执行某些操作才能使其使用 Newtonsoft.Json.dll?

采纳答案by TARKUS

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.

感谢您的指针和链接。经过一番挣扎,我得到了它的工作。最后发生的事情是我的朋友,.NET 专家,通过 Skype 向我询问了将我的项目部署到目标服务器的正确方法。我不明白你的 Build 有一个单独的文件夹。我制作了一个“构建部署包”作为一个 zip 文件。然后我将它解压缩到我的硬盘上,并将它放到 Web 服务器上的一个干净文件夹中(实际上,我将它上传到了根目录),瞧,它起作用了。

回答by Gonzalo.-

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

另外,看看这个问题:reference dll not copying to bin with deployment project requires error

回答by k3yz101

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

此问题的另一个可能原因是项目正在使用 NuGet 包并且它们尚未恢复(下载)。

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

它们可能需要在 Visual Studio 中还原,或者您可以使用 nuget.exe 命令行可执行文件来还原包。

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

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