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

8

50

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?

Vinegarish answered 23/10, 2012 at 16:34 Comment(6)
So the framework your project is pointing is definitely NOT the Client Profile version, right?Tymothy
As the user above me stated, make sure your project is targeting .NET 4 and not .NET 4 client profile.Session
@Tymothy It is a .NET Framework 4 Client Profile but: (1) I am not interested in converting it to a .NET Framework 4. (2) If you read that thread, you'll notice that the tips there didn't help even for those who had the full .NET Framework 4. Surely there must be a way to use JavaScriptSerializer in a Client Profile, right?Vinegarish
@TejasSharma If I try to change the Target framework from .NET Framework 4 Client Profile to .NET Framework 4, I get a warning that horrible things might happen to my project... So when asked "Are you sure you want to change the Target Framework for this project?", of course I click No.Vinegarish
Have you tried deleting and then re-adding the System.Web.Extensions reference?Klemperer
I've used DataContractJsonSerializer (which lives in the System.Runtime.Serialization.Json namespace) when I've not been able to use JavaScriptSerializer (such as in wcf projects). Just a thought...Klemperer
S
13

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.

Session answered 23/10, 2012 at 16:51 Comment(2)
Referencing the 3.5 version in C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5 did the trick. Thank you!Vinegarish
#4445403 newtonsoft.json is another option.Herbherbaceous
A
55

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.

Aerobe answered 31/3, 2015 at 19:35 Comment(1)
I have added a reference to System.Web.Extensions , and now both of them are underlinedNablus
I
42

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

enter image description here

For Ref.

Inquisitorial answered 27/8, 2017 at 12:22 Comment(2)
Please add steps on how to reach this menu.Doubloon
@Doubloon The menu can be reached via Project -> Add Reference.Betts
S
13

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.

Session answered 23/10, 2012 at 16:51 Comment(2)
Referencing the 3.5 version in C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5 did the trick. Thank you!Vinegarish
#4445403 newtonsoft.json is another option.Herbherbaceous
I
7

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

Impressure answered 20/1, 2016 at 4:48 Comment(1)
Everyone is saying to "add a reference to System.Web.Extensions" however as a complete beginner, I have no idea how to do that. To improve your answer, explain HOW to do it and assume your reader has no experience writing C# code.Vanover
H
1

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

NuGet- > Install-Package Newtonsoft.Json

Herbherbaceous answered 11/9, 2015 at 19:54 Comment(0)
L
0

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

Longsufferance answered 16/11, 2021 at 4:18 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Routinize
A
0

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

Alisealisen answered 22/9, 2022 at 10:18 Comment(0)
K
0

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

Kandrakandy answered 26/5, 2023 at 6:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.