ASP.NET C #: JavascriptSerializer not found

I am trying to use a JavascriptSerializer object in ASP.NET v4.0 with C #. I do not use Visual Studio - it is on a real IIS7 server. I can access this object very well using VB on the same web server, so I know that the required 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 the following:

 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 the following:

 JavaScriptSerializer obj_serializer = new JavascriptSerializer(); 

This is the last line of code causing the above error.

reference

+5
source share
5 answers

I don't know if you typed the string incorrectly, but this is a JavaScriptSerializer, not a JavascriptSerializer (Capital S in Script).

+2
source

You need to add the link in System.Web.Extensions.dll to your application. System.Web.Extensions is the namespace that contains the JavaScriptSerializer class. Then add the using directive to use the System.Web.Extensions namespace as follows:

 using System.Web.Extensions; 

You can also declare your JavaScriptSerializer as follows:

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

therefore, I know that the necessary DLLs are present and correctly configured.

They can be deployed in this project. Have you tried setting CopyLocal to true in link properties in VS and redistributing it?

0
source

Instead, you may need to:

 using System.Web.Script.Serialization; 
0
source

Solve the problem → Just take the link Step-> BY-> Step

1 .-> Go to the Reference your project file.

2 .-> Right click, then go to Add Reference

3 .-> Go to Framework

4 .-> Then take Reference ---> System.Web.Extensions

5 .-> The problem is resolved.

0
source

All Articles