Question

I'm trying to use the JavascriptSerializer object in ASP.NET v4.0 with C#. I'm not using Visual Studio--this is on a live IIS7 server. I can access this object just fine using VB on this same web server, so I know the requisite DLLs are present and correctly configured.

But when I try to use this object in C#, I get this error: The type or namespace name 'JavascriptSerializer' could not be found

In my class file, I have this:

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

In web.config, I have this:

<assemblies>
    <add assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</assemblies>

In my default.aspx.cs file, I have this:

JavaScriptSerializer obj_serializer = new JavascriptSerializer();

It's this last line of code that is causing the above referenced error.

Help?

Was it helpful?

Solution 3

I don't know if you just incorrectly typed the line, but it's JavaScriptSerializer, not JavascriptSerializer (Capital S in Script).

OTHER TIPS

You need to add a reference to System.Web.Extensions.dll in your application. System.Web.Extensions is the namespace that contains the JavaScriptSerializer class. Then add a using directive to use the namespace System.Web.Extensions like so:

using System.Web.Extensions;

You can also declare your JavaScriptSerializer like this:

var serializer = new System.Web.Extensions.JavaScriptSerializer();

To Solve The Problem -> Just Take reference Step->BY->Step

1.-> Go To Reference of Your project File.

2.-> Right click Then Go To Add Reference

3.-> Go To Framework

4.-> Then Take The Reference--->System.Web.Extensions

5.-> Problem Solved.

Instead you might need:

using System.Web.Script.Serialization;

so I know the requisite DLLs are present and correctly configured.

They may be bin deployed to that project. Have you tried setting CopyLocal to true in the properties of the reference in VS and redeploying?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top