C# 错误 CS0234:命名空间“System.Web”中不存在类型或命名空间名称“Script”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13035192/
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-08-10 01:24:51  来源:igfitidea点击:

error CS0234: The type or namespace name 'Script' does not exist in the namespace 'System.Web'

c#visual-studio-2010javascriptserializerjsonserializer

提问by scatmoi

I am trying to use JavaScriptSerializerin my application.

我正在尝试JavaScriptSerializer在我的应用程序中使用。

I initially received

我最初收到

Cannot find JavaScriptSerializer

找不到 JavaScriptSerializer

and I solved it by adding:

我通过添加解决了它:

using System.Web.Script.Serialization;

But then the sub-keyword Scriptis underlined with a blue line:

但是子关键字Script用蓝线下划线:

The type or namespace 'Script' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)

命名空间“System.Web”中不存在类型或命名空间“Script”(您是否缺少程序集引用?)

So I added to the project a reference to:

所以我在项目中添加了对以下内容的引用:

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Web.Extensions.dll

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Web.Extensions.dll

That didn't help. I am still receiving the same blue underline with same error. The reference is marked with an exclamation mark yellow warning:

那没有帮助。我仍然收到相同的蓝色下划线和相同的错误。引用标有感叹号黄色警告:

enter image description here

在此处输入图片说明

I tried the suggested solutions on this thread, but as @user781490 indicated, they didn't help in my situation.

我在此线程上尝试了建议的解决方案,但正如@user781490 指出的那样,它们对我的情况没有帮助。

Any idea how to resolve this?

知道如何解决这个问题吗?

采纳答案by Tejas Sharma

I found this MSDN forum post which suggests two solutions to your problem.

我发现这篇 MSDN 论坛帖子为您的问题提出了两种解决方案

First solution (not recommended):

第一种解决方案(不推荐):

Find the .Net Framework 3.5 and 2.0 folder

Copy System.Web.Extensions.dll from 3.5 and System.Web.dll from 2.0 to the application folder

Add the reference to these two assemblies

Change the referenced assemblies property, setting "Copy Local" to true And build to test your application to ensure all code can work

找到 .Net Framework 3.5 和 2.0 文件夹

将 System.Web.Extensions.dll 从 3.5 和 System.Web.dll 从 2.0 复制到应用程序文件夹

添加对这两个程序集的引用

更改引用的程序集属性,将“Copy Local”设置为 true 并构建以测试您的应用程序以确保所有代码都可以工作

Second solution (Use a different class / library):

第二种解决方案(使用不同的类/库):

The user who had posted the question claimed that Uri.EscapeUriStringand How to: Serialize and Deserialize JSON Datahelped him replicate the behavior of JavaScriptSerializer.

发布问题的用户声称,Uri.EscapeUriString以及如何:序列化和反序列化 JSON 数据帮助他复制了JavaScriptSerializer.

You could also try to use Json.Net. It's a third party library and pretty powerful.

您也可以尝试使用Json.Net。这是一个第三方库,非常强大。

回答by Costa Zachariou

I had the same. Script been underlined. I added a reference to System.Web.Extensions. Thereafter the Script was no longer underlined. Hope this helps someone.

我有同样的。脚本已加下划线。我添加了对 System.Web.Extensions 的引用。此后脚本不再有下划线。希望这可以帮助某人。

回答by Enkode

Since JsonSerializer is deprecated in .Net 4.0+ I used http://www.newtonsoft.com/jsonto solve this issue.

由于 JsonSerializer 在 .Net 4.0+ 中已弃用,我使用http://www.newtonsoft.com/json来解决这个问题。

NuGet- > Install-Package Newtonsoft.Json

NuGet-> 安装包 Newtonsoft.Json

回答by Usman

Just Add reference to System.Web.Extensions and happy to go.

只需添加对 System.Web.Extensions 的引用就可以了。

回答by Siddhartha

Add System.Web.Extensions as a reference to your project

添加 System.Web.Extensions 作为对您项目的引用

enter image description here

在此处输入图片说明

For Ref.

对于参考。