310

I cannot seem to find the JavaScriptSerializer object nor the the System.Web.Script.Serialization namespace within Visual Studio 2010. I need to serialize something to JSON what am I supposed to use?

And yes, I already included the System.Web.Extensions (in System.Web.Extensions.dll) within the project. Which is why I am shocked?

  • I do know System.Web.Extensions was marked as obsolete in 3.5
asked Aug 9, 2011 at 18:15
2
  • 5
    I have the same problem, and I gotta say the answers are pretty useless. I am targeting the ".NET Framework 4", not ".NET 4 Client Profile". I have referenced the System.Web.Extensions assembly. But when I try using the System.Web.Script.Serialization namespace, VS 2010 tells me "The type or namespace Script does not exist in the namespace System.Web". Has anyone found a real solution for this? I'm stumped! Commented Nov 16, 2011 at 18:28
  • Related post here. Commented Nov 12, 2017 at 1:17

12 Answers 12

545

Check if you included the .net 4 version of System.Web.Extensions - there's a 3.5 version as well, but I don't think that one works.

These steps work for me:

  1. Create a new console application
  2. Change the target to .net 4 instead of Client Profile
  3. Add a reference to System.Web.Extensions (4.0)
  4. Have access to JavaScriptSerializer in Program.cs now :-)
Nico Schertler
32.7k4 gold badges45 silver badges76 bronze badges
answered Nov 25, 2011 at 6:20

1 Comment

in vb.net don't forget "new" and ( ) like : Dim JsonConvert As New JavaScriptSerializer()
141
  1. Right click References and do Add Reference, then from Assemblies->Framework select System.Web.Extensions.
  2. Now you should be able to add the following to your class file:
 using System.Web.Script.Serialization;
answered Mar 13, 2013 at 16:44

Comments

43

From the first search result on google:

http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx

JavaScriptSerializer Class

Provides serialization and deserialization functionality for AJAX-enabled applications.

Inheritance Hierarchy

System.Object

System.Web.Script.Serialization.JavaScriptSerializer

Namespace: System.Web.Script.Serialization

Assembly: System.Web.Extensions (in System.Web.Extensions.dll)

So, include System.Web.Extensions.dll as a reference.

answered Aug 9, 2011 at 18:18

1 Comment

Two years later, on a totally unrelated project: it also helps if you capitalize it correctly >.> (it's not JavascriptSerializer).
32

I'm using Visual Studio 2015 and finally ran across this post.

Yes in order to use

JavaScriptSerializer json = new JavaScriptSerializer();

You must right click on references and under Assemblies --> Framework choose

System.Web.Extensions

Then add in your reference

using System.Web.Script.Serialization;
answered Sep 17, 2015 at 0:44

Comments

14

This is how to get JavaScriptSerializer available in your application, targetting .NET 4.0 (full)

using System.Web.Script.Serialization;

This should allow you to create a new JavaScriptSerializer object!

Gonzalo.-
12.7k5 gold badges53 silver badges84 bronze badges
answered Aug 28, 2012 at 8:33

1 Comment

Script does not exist
13
using System.Web.Script.Serialization; 

is in assembly : System.Web.Extensions (System.Web.Extensions.dll)

answered Jan 20, 2014 at 9:45

Comments

9

Are you targeting the .NET 4 framework or the .NET 4 Client Profile?

If you're targeting the latter, you won't find that class. You also may be missing a reference, likely to an extensions dll.

answered Aug 9, 2011 at 18:18

3 Comments

.NET Framework 4. And I already have 'System.Web.Extensions' included in the project
Is this a project you've upgraded from an earlier version of .net?
I'm having this issue with a project I upgraded. It doesn't appear to be resolved by using the original .net version (3.5) though...
9

For those who seem to be following the answers above but still have the problem (e.g., see the first comment on the poster's question):

You are probably working in a solution with many projects. The project you appear to be working in references other projects, but you are actually modifying a file from one of the other projects. For example:

  • project A references System.Web.Extensions
  • project A references project B

But if the file you are modifying to use System.Web.Script.Serialization is in project B, then you will need to add a reference to System.Web.Extension in project B as well.

answered May 2, 2013 at 22:58

Comments

8

Did you include a reference to System.Web.Extensions? If you click on your first link it says which assembly it's in.

answered Aug 9, 2011 at 18:18

1 Comment

In that case maybe check out @Christopher's answer.
5

You have to add the reference to the project.

In Assemblies, there is a System.Web.Extensions Add that.

Once that is done put:

 using System.Web;
 using System.Web.Script;
 using System.Web.Script.Serialization;

That worked for me.

answered Feb 21, 2013 at 15:51

Comments

5

You can use another option which is the Newtonsoft.Json, you can install it from NuGet Package Manager.

Tools>> Nuget Package Manager>> Package Manager Console by issuing command

Install-Package Newtonsoft.Json

or

by using the GUI at Tools>> Nuget Package Manager>> Manage NuGet Packages for Solution...

enter image description here

Iztoksson
9911 gold badge17 silver badges33 bronze badges
answered Jun 16, 2017 at 14:18

1 Comment

Note that this is Microsoft's documented recommendation. On .Net Core, Microsoft no longer even offers JavaScriptSerializer (nor the rest of System.Web.Extensions).
3

Just so you know, I am using Visual Studio 2013 and have had the same problem until I used the Project Properties to switch to 3.5 framework and back to 4.5. This for some reason registered the .dll properly and I could use the System.Web.Extensions.

enter image description here

enter image description here

answered Oct 29, 2015 at 22:42

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.