[英]error CS0234: The type or namespace name 'Script' does not exist in the namespace 'System.Web'
I am trying to use JavaScriptSerializer
in 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 Script
is 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”中不存在类型或命名空间“脚本”(您是否缺少程序集引用?)
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.Z06416233FE5EC4C8133122E4ZAB2
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:
引用标有感叹号黄色警告:
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?知道如何解决这个问题吗?
I had the same. 我有同样的。 Script been underlined.
脚本被强调了。 I added a reference to System.Web.Extensions.
我添加了对System.Web.Extensions的引用。 Thereafter the Script was no longer underlined.
此后,脚本不再加下划线。 Hope this helps someone.
希望这有助于某人。
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
找到.Net Framework 3.5和2.0文件夹
Copy System.Web.Extensions.dll from 3.5 and System.Web.dll from 2.0 to the application folder
将System.Web.Extensions.dll从3.5和System.Web.dll从2.0复制到应用程序文件夹
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
更改引用的程序集属性,将“Copy Local”设置为true并构建以测试应用程序以确保所有代码都能正常工作
Second solution (Use a different class / library): 第二种解决方案(使用不同的类/库):
The user who had posted the question claimed that Uri.EscapeUriString
and How to: Serialize and Deserialize JSON Data helped him replicate the behavior of JavaScriptSerializer
. 发布问题的用户声称
Uri.EscapeUriString
和如何:序列化和反序列化JSON数据帮助他复制了JavaScriptSerializer
的行为。
You could also try to use Json.Net . 您也可以尝试使用Json.Net 。 It's a third party library and pretty powerful.
它是第三方图书馆,非常强大。
只需添加对System.Web.Extensions的引用即可。
Since JsonSerializer is deprecated in .Net 4.0+ I used http://www.newtonsoft.com/json to solve this issue. 由于JsonSerializer在.Net 4.0+中被弃用,我使用http://www.newtonsoft.com/json来解决这个问题。
NuGet- > Install-Package Newtonsoft.Json NuGet-> Install-Package Newtonsoft.Json
我试过了,你可以添加参考 web.extensions(我使用 .Net 框架 4.5)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.