C# – Cannot find JavaScriptSerializer in .Net 4.0

cjsonserializervisual studio

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

Best Answer

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 :-)