Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET C#: JavascriptSerializer could not be found

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?

like image 993
Octavient Avatar asked Apr 04 '13 17:04

Octavient


People also ask

What is ASP.NET C?

ASP.NET is an open source web framework, created by Microsoft, for building modern web apps and services with . NET. ASP.NET is cross platform and runs on Linux, Windows, macOS, and Docker.

Can I use .NET with C?

. NET Framework is an object oriented programming framework meant to be used with languages that it provides bindings for. Since C is not an object oriented language it wouldn't make sense to use it with the framework.

What is ASP.NET C# used for?

ASP.NET is a server-side technology used for developing dynamic websites and web applications. ASP.NET aids developers to create web applications by using HTML, CSS, and JavaScript. ASP.NET is the latest version of Active Server Pages, which Microsoft developed to build websites.

What is .NET and C#?

C# is a programming language, . NET is a blanket term that tends to cover both the . NET Framework (an application framework library) and the Common Language Runtime which is the runtime in which . NET assemblies are run. C# is the language.


2 Answers

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();
like image 78
Cameron Tinker Avatar answered Oct 21 '22 09:10

Cameron Tinker


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.

like image 22
Sabuj Sarker Avatar answered Oct 21 '22 11:10

Sabuj Sarker