Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I reference System.Runtime.Serialization.Json in C#

I want to use an API to get info from the interwebz. The API returns data in Json format.

  1. I'm running Microsoft Visual Studio C# 2010 Express addition.
  2. It appears that I have the .NET Framework 4 Client Profile set as my "Target framework" but I'm honestly not sure exactly what this means.
  3. This is a Windows Forms Application...

Not much code to show because I can't really get started without the appropriate using statement...

using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using System.Net; using System.Runtime.Serialization.Json; 

I get this error:

The type or namespace name 'Json' does not exist in the namespace 'System.Runtime.Serialization' (are you missing an assembly reference?)

Am I missing a DLL file or something? Based on my hours of fruitlessly searching for solutions, I understand that the .NET 4.xx should already have the tools needed to parse up a Json formatted string?

like image 381
Methodician Avatar asked Mar 07 '14 16:03

Methodician


People also ask

What is system runtime serialization?

Serialization is the process of converting an object or a graph of objects into a linear sequence of bytes for either storage or transmission to another location.

What is JSON serialization?

Serialization is the process of converting . NET objects such as strings into a JSON format and deserialization is the process of converting JSON data into . NET objects.

How do I deserialize JSON?

A common way to deserialize JSON is to first create a class with properties and fields that represent one or more of the JSON properties. Then, to deserialize from a string or a file, call the JsonSerializer. Deserialize method.


2 Answers

The System.Runtime.Serialization.Json Namespace is in two different DLL's depending on your .net framework.

In .NET 3.5 It is in System.ServiceModel.Web.dll

In .NET 4.0 and above It is in System.Runtime.Serialization.dll.

Make sure you have added the correct DLL as a reference in your project and add using System.Runtime.Serialization.Json; to the top of your code file.

EDIT - Consider using JSON.NET

Even though the .NET Framework supplies its own JSON Serialization and Deserialization namespaces (DataContractJsonSerializer and JavaScriptSerializer) you should investigate whether you would be better off using JSON.NET.

JSON.NET is easier to use, better performance and has far more features. http://www.newtonsoft.com/json/help/html/JsonNetVsDotNetSerializers.htm

like image 108
CathalMF Avatar answered Sep 23 '22 17:09

CathalMF


you need to import System.Runtime.Serialization dll from reference

like image 24
Eanthmue Avatar answered Sep 20 '22 17:09

Eanthmue