简体   繁体   English

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

[英]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. 希望这有助于某人。

Add System.Web.Extensions as a reference to your project 添加System.Web.Extensions作为项目的引用

在此输入图像描述

For Ref. 对于参考

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)

I have a similar issue.我有一个类似的问题。 Fail on "using System.Threading.Channels;" “使用 System.Threading.Channels;”失败

my solution is to add reference of " System.Threading.Tasks.Extensions.dll"我的解决方案是添加“System.Threading.Tasks.Extensions.dll”的引用System.Threading.Tasks.Extensions.dll

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 CS0234:类型或名称空间名称“ WebPages”在名称空间“ System.Web”中不存在(您是否缺少程序集引用?) - CS0234: The type or namespace name 'WebPages' does not exist in the namespace 'System.Web' (are you missing an assembly reference?) 错误CS0234:名称空间“System.Runtime.InteropServices”中不存在类型或命名空间名称“CustomMarshalers” - Error CS0234: The type or namespace name 'CustomMarshalers' does not exist in the namespace 'System.Runtime.InteropServices' 错误CS0234:类型或名称空间名称'AccountManagement'在名称空间'System.DirectoryServices'中不存在 - error CS0234: The type or namespace name 'AccountManagement' does not exist in the namespace 'System.DirectoryServices' 错误 CS0234:命名空间“System.Data”VSTS (DevOps) 中不存在类型或命名空间名称“实体” - Error CS0234: The type or namespace name 'Entity' does not exist in the namespace 'System.Data' VSTS (DevOps) CS0234:类型或名称空间名称“ Description”在名称空间“ System.Web.Http”中不存在(您是否缺少程序集引用?) - CS0234: The type or namespace name 'Description' does not exist in the namespace 'System.Web.Http' (are you missing an assembly reference?) CS0234:命名空间“System.Runtime.Serialization.Formatters”中不存在类型或命名空间名称“Soap” - CS0234: The type or namespace name 'Soap' does not exist in the namespace 'System.Runtime.Serialization.Formatters' 错误CS0234名称空间名称'编码'不存在 - ERROR CS0234 namespace name 'Encodings' does not exist 错误 CS0234 命名空间“Xamarin.Forms.Platform”中不存在类型或命名空间名称“Android” - Error CS0234 The type or namespace name 'Android' does not exist in the namespace 'Xamarin.Forms.Platform 错误 CS0234 命名空间“Microsoft”中不存在类型或命名空间名称“Reporting”(您是否缺少程序集引用?) - Error CS0234 The type or namespace name 'Reporting' does not exist in the namespace 'Microsoft' (Are you missing an assembly reference?) 错误CS0234类型或名称空间名称'SendTextMessageAsync'在名称空间'Telegram.Bot'中不存在 - Error CS0234 The type or namespace name 'SendTextMessageAsync' does not exist in the namespace 'Telegram.Bot'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM