scatmoi
scatmoi

Reputation: 2028

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.

I initially received

Cannot find JavaScriptSerializer

and I solved it by adding:

using System.Web.Script.Serialization;

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

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

So I added to the project a reference to:

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.

Any idea how to resolve this?

Upvotes: 52

Views: 137469

Answers (8)

sara asadi
sara asadi

Reputation: 1

I had a similar problem but with two projects I'd made myself. the problem was mismatching the .net framework version.

Upvotes: 0

Jamie
Jamie

Reputation: 111

I have a similar issue. Fail on "using System.Threading.Channels;"

my solution is to add reference of " System.Threading.Tasks.Extensions.dll" System.Threading.Tasks.Extensions.dll

Upvotes: 0

Crom brow 2e36
Crom brow 2e36

Reputation: 1

i have try it you could add reference web.extensions ( i using .Net framwork 4.5)

Upvotes: 0

Tejas Sharma
Tejas Sharma

Reputation: 3440

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

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

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.

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

Upvotes: 13

Siddhartha
Siddhartha

Reputation: 1563

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

enter image description here

For Ref.

Upvotes: 44

Usman
Usman

Reputation: 2577

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

Upvotes: 7

Enkode
Enkode

Reputation: 4803

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

NuGet- > Install-Package Newtonsoft.Json

Upvotes: 1

Costa Zachariou
Costa Zachariou

Reputation: 917

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.

Upvotes: 55

Related Questions