Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Json does not exist in the namespace System

In this tutorial: http://www.asp.net/web-api/videos/getting-started/custom-validation Jon uses

dynamic error = new JsonObject();

with

using System.Json;

I guess it's the JsonObject here: http://msdn.microsoft.com/en-us/library/system.json.jsonobject(v=vs.110).aspx located in:

  • Namespace: System.Json
  • Assembly: System.Runtime.Serialization (in System.Runtime.Serialization.dll)

I've added System.Runtime.Serialization a reference but still cannot find System.Json.

Am I reading the Microsoft docs wrong? (I'm using .NET 4.5)

like image 958
Cotten Avatar asked Oct 12 '12 12:10

Cotten


3 Answers

Try this:

PM> Install-Package System.Json -Version 4.0.20126.16343 

Per: http://nuget.org/packages/System.Json

It worked!

If you have questions on how to add enter nuget code, please follow the link below: http://docs.nuget.org/docs/start-here/using-the-package-manager-console

like image 61
slamsal Avatar answered Oct 27 '22 14:10

slamsal


http://www.webcosmoforums.com/asp/32551-type-namespace-name-json-does-not-exist-namespace-system-runtime-serialization.html

Most likely you are missing a reference to System.ServiceModel.Web

Make sure your application is targeting the .Net 4.5 framework in the project properties.

The System.Json objects are only available in 4.5

Edit:

Use Nuget to install system.json : 'Install-Package System.Json'

How to parse JSON without JSON.NET library?

like image 27
Darbio Avatar answered Oct 27 '22 15:10

Darbio


The Json object works only from Controller class and not outside. Even if we refer System.Web.MVC outside controller, we have access only to JsonResult and not to Json as Json object is protected object of JsonResult. Please refer the below documentation which explains that,

http://msdn.microsoft.com/en-us/library/dd504936(v=vs.118).aspx

like image 27
balaji palamadai Avatar answered Oct 27 '22 13:10

balaji palamadai