3

when trying to initialize a variable

JavaScriptSerializer javascriptSerializer = new JavaScriptSerializer();

I am getting the following error : 'JavaScriptSerializer' could not be found .net core. i also tried to include the namespace 'System.Web.Script.Serialization' but even that is not found.

How to solve it?

4
  • 2
    that doesn't exist in .net core. use JSON.NET Commented May 28, 2018 at 20:18
  • Is there any particular reason you need to use JavaScriptSerializer? Commented May 28, 2018 at 20:59
  • converting one of my .net project to .net core. there i faced this issue. so i don't want to use 'JsonConvert' Commented May 31, 2018 at 9:04
  • You should not introduce an System.Web dependency on a .NET Core project. If a new project you should use .NET Core 2.0 + and Newtonsoft.Json comes with it. If you are not able to use Newtonsoft.Json even installing via NuGet it and seeing the dependency I think your problem is another Commented May 31, 2018 at 13:51

1 Answer 1

1

Adding it via Nuget may solve your problem. Open the Nuget package manager and type in the following command:

Install-Package WebApiContrib.Formatting.JavaScriptSerializer

Edit:

Newtonsoft.Json is the standard nowadays. It is also known as Json.Net.

Sign up to request clarification or add additional context in comments.

2 Comments

@AdithyaSai: Use Newtonsoft.Json.
I cant find an JavaScriptSerializer in that package only, JavaScriptSerializerFormatter. I'm using dotnet core 6.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.