What is a TLB file?

What is a TLB file?


What are tlb files?

A TLB file is a small file to help accessing a DLL. This is true for COM or DCOM object. You will use TLB files if for example you make a DLL with Visual Studio 2010 (C# or VB) and want to make if COM visible.
And the best example is when you make a DLL from Visual Studio using any new Framework such as NET 2.0, 3.0, 3.5, 4.0 or 4.5 and wish to make if useable inside any VBA editor (from Excel , Autocad, MicroStation, …)


How to create a TLB file?


First you need a DLL (COM or DCOM DLL). It is not important how you made your DLL (C# or VB). For example:
C: \temp\test.dll

Now, to create a TLB file and to be able to use it, you have to start a command line and run something like this if your DLL is a x86 type:
C:\Windows\Microsoft.NET\Framework\<VERSION>\REGASM.exe C: \temp\test.dll
/tlb:C:\temp\test.dll


If your DLL is a x64 type:
C:\Windows\Microsoft.NET\Framework64\<VERSION>\REGASM.exe C: \temp\test.dll
/tlb:C:\temp\test.dll

How to unregister or delete a TLB ?


This will only work if you previously register your DLL/TLB correctly. You also have to call the same Framework.  Adding the “/u” will do, check this example:
C:\Windows\Microsoft.NET\Framework\<VERSION>\REGASM.exe /u C: \temp\test.dll
/tlb:C:\temp\test.dll

Or
C:\Windows\Microsoft.NET\Framework64\<VERSION>\REGASM.exe /u C: \temp\test.dll
/tlb:C:\temp\test.dll

If your TLB is still available, try to delete it from the registry using REGEDIT. Normally, the entry is inside HKEY_CLASSES_ROOT.

You just need to search for “C:\temp\test.dll”

What do I need to know?

Well this text doesn’t say everything but I hope is helped a few of you.


References :

From MSDN :
COM, DCOM, and Type Libraries

Regasm.exe (Assembly Registration Tool)

Serialization And Deserialization


Serialization is the process of converting an object into a sequence of bytes and Deserialization is the process of converting a previously serialized sequence of bytes into an object. It enables you to save the state of an object and reconstruct it as needed.
Object Serialization is a process through which an object's state is transformed into some serial data format, such as XML or binary format, 
Some good uses for serialization/deserialization include: 
  1. Storing user preferences in an object.
  2. Maintaining security information across pages and applications.
  3. Modification of XML documents without using the DOM.
  4. Passing an object from on application to another.
  5. Passing an object from one domain to another.
  6. Passing an object through a firewall as an XML string. 


You can send the object to a remote application, using a Web Service.

Types related to Serialization and Deserialization is available in System.Runtime.Serialization.Formatters.Binary; namespace.
Binary serialization
Steps for serializing an object are as follows:

1.  Create a stream object.
2. Create a BinaryFormatter Object.
3. Call the BinaryFormatter.Serialize() method.

Steps for deserializing an object are as follows:

1. Create a stream object to read the serialized output.
2. Create a BinaryFormatter object.
3. Call the BinaryFormatter.Deserialize() method to deserialize the object, and cast it to the correct type.

Example
using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace ConsoleApplication1
{
    class Program
    {
        public static void SerializeData()
        {
            string str = "Welcome at TutorialRide.";
            // Create file to save the data.
            FileStream fs = new FileStream(@"D:\MyDataFile.txt", FileMode.Create);
            // BinaryFormatter object will perform the serialization
            BinaryFormatter bf = new BinaryFormatter();
            // Serialize() method serializes the data to the file
            bf.Serialize(fs, str);
            // Close the file
            fs.Close();
        }
        public static void DeSerializeData()
        {
            // Open file to read the data
            FileStream fs = new FileStream(@"D:\MyDataFile.txt", FileMode.Open);
            // BinaryFormatter object performs the deserialization
            BinaryFormatter bf = new BinaryFormatter();
            // Create the object to store the deserialized data
            string data = "";    
            data = (string)bf.Deserialize(fs);
            //// Close the file
            fs.Close();
            // Display the deserialized strings
            Console.WriteLine("Your deserialize data is ");
            Console.WriteLine(data);
        }  
        static void Main(string[] args)
        {
            SerializeData();
            DeSerializeData();
            Console.ReadLine();      
        }
    }
}


Run the application and open the MyDataFile.txt file, you will see the contents of the string you stored along with by binary information which seems as garbage in Notepad.



The string information stored as ASCII text and combined with binary bytes before and after the text to describe the data for the deserialization.

The above example is simply stores the string object as serialized data but you can serialize is more complex information such as the current date and time, custom class.


Serialization of custom classes
You can serialize and de-serialize custom classes by adding the Serializable attribute to the class. We will create a class and apply Serializable attribute with this class. When your class is serialized, the framework will serializes all members, including private members. If you want that particular member should not serialized during serialization process, then you can use [NonSerialized] attribute as given below.

[NonSerialized] public float total;

Example
using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace ConsoleApplication1
{
    [Serializable]
    class Employee
    {
        public int EmpID;
        public string EmpName;
        public string Address;
        public Employee(int id,string name, string EmpAdd)
        {
            EmpID = id;
            EmpName = name;
            Address = EmpAdd;
        }
    }
    class Program
    {
        public static void SerializeData()
        {
            Employee obj = new Employee(1,"Raj","Pune");      
            // Create file to save the data.
            FileStream fs = new FileStream(@"D:\Employee.txt", FileMode.Create);
            // BinaryFormatter object will perform the serialization
            BinaryFormatter bf = new BinaryFormatter();
            // Serialize() method serializes the data to the file
            bf.Serialize(fs, obj);
            // Close the file
            fs.Close();
        }
        public static void DeSerializeData()
        {
            Employee emp;
            // Open file to read the data
            FileStream fs = new FileStream(@"D:\Employee.txt", FileMode.Open);
            // BinaryFormatter object performs the deserialization
            BinaryFormatter bf = new BinaryFormatter();
            // Create the object to store the deserialized data          
            emp = (Employee)bf.Deserialize(fs);
            int id = emp.EmpID;
            string name = emp.EmpName;
            string Empadd = emp.Address;
            //// Close the file
            fs.Close();
            // Display the deserialized strings
            Console.WriteLine("Your deserialize data is ");
            Console.WriteLine("EmpID = "+id);
            Console.WriteLine("Emp Name = " + name);
            Console.WriteLine("Emp Address = " + Empadd);
        }  
        static void Main(string[] args)
        {
            SerializeData();
            DeSerializeData();
            Console.ReadLine();      
        }
    }
}


Run the above application and open the Employee.txt file, you will see something like as given below. The Employee class and its member are serialized and extra binary information is also appended with employee class member. When you de-serialized the previously stored information, you will get the original data.



XML serialization
XML serialization serializes an object into an XML document.

System.Xml.Serialization namespace provides methods for converting objects into XML and write into XML files. XML serialization provides greater interoperability and better forward-compatibility.

Steps for serializing an object are as follows:

1. Create a stream.
2. Create an XmlSerializer object.
3. Use XmlSerializer.Serialize() method to serialize the object.

Steps for de-serializing an object are as follows:

1. Create a stream.
2. Create an XmlSerializer object.
3. Call the XmlSerializer.Deserialize() method to deserialize the object.

First we will serialize the DateTime object then custom class.

Example
using System;
using System.IO;
using System.Xml.Serialization;
namespace ConsoleApplication1
{
    class Program
    {
        public static void SerializeData()
        {     
            // Create file to save the data.
            FileStream fs = new FileStream(@"D:\MyXMLFile.txt", FileMode.Create);     
            //XmlSerializer object will perform the serialization
            XmlSerializer xmlObj = new XmlSerializer(typeof(DateTime));
            // Serialize mehtod serialize the data to the file
            xmlObj.Serialize(fs, System.DateTime.Now);
            // Close the file
            fs.Close();
        }
        public static void DeSerializeData()
        {
            // Open file to read the data
            FileStream fs = new FileStream(@"D:\MyXMLFile.txt", FileMode.Open);     
            // XmlSerializer object to perform the deserialization
            XmlSerializer xs = new XmlSerializer(typeof(DateTime));
            // Use the XmlSerializer object to deserialize the data from the file
            DateTime time = (DateTime)xs.Deserialize(fs);
            // Close the file
            fs.Close();
            // Display the deserialized time
            Console.WriteLine("Day: " + time.DayOfWeek + ", Time: " + time.TimeOfDay.ToString()+", Date: "+time.Date.ToShortDateString());
        }
        static void Main(string[] args)
        {
            SerializeData();
            DeSerializeData();
            Console.ReadLine();
        }
    }
}



XML serialization of custom class
To create a class that can be serialized by using XML serialization, you must keep in mind the following things:


  • XML serialization only serializes public fields and properties not private members.
  • XML serialization does not include any type information.
  • Class must be declared as public.
  • Class should not contain parameterized constructor to serialize an object.
  • ReadOnly properties are not serialized.
Example
using System;
using System.IO;
using System.Xml.Serialization;
namespace ConsoleApplication1
{
    public class Employee
    {
        public int EmpID{get;set;}
        public string EmpName { get; set; }
        public string Address { get; set; }
        public Employee()
        {
            EmpID = 0;
            EmpName = "N/A";
            Address = "N/A";
        }
    }

    class Program
    {
        public static void SerializeData(Employee emp)
        {     
            // Create file to save the data.
            FileStream fs = new FileStream(@"D:\MyXMLFile.txt", FileMode.Create);     
            //XmlSerializer object will perform the serialization
            XmlSerializer xmlObj = new XmlSerializer(typeof(Employee));
            // Serialize mehtod serialize the data to the file
            xmlObj.Serialize(fs, emp);
            // Close the file
            fs.Close();
        }
        public static void DeSerializeData()
        {
            // Open file to read the data
            FileStream fs = new FileStream(@"D:\MyXMLFile.txt", FileMode.Open);     
            // XmlSerializer object to perform the deserialization
            XmlSerializer xs = new XmlSerializer(typeof(Employee));
            // Use the XmlSerializer object to deserialize the data from the file
            Employee emp = (Employee)xs.Deserialize(fs);
            // Close the file
            fs.Close();
            // Display the de-serialized data
            Console.WriteLine("Employee ID = "+emp.EmpID);
            Console.WriteLine("Employee Name = " + emp.EmpName);
            Console.WriteLine("Employee Address = " + emp.Address);
        }
        static void Main(string[] args)
        {
            Employee empObj = new Employee();
            Console.WriteLine("Enter employee ID");
            empObj.EmpID = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Enter employee Name");
            empObj.EmpName = Console.ReadLine();
            Console.WriteLine("Enter employee address");
            empObj.Address = Console.ReadLine();
            SerializeData(empObj);
            DeSerializeData();
            Console.ReadLine();
        }
    }
}


The output after the serialization is: 



In the above XML file, the Head tag of the XML created is same as the name of class and the subtag names are same as the properties in class Employee. Each public property is displayed in the form of Tags in the XML created on serialization. We can see in XML file that only public fields are displayed.


Attributes in XML Serialization
Some important attributes in XML Serialization are:


  • XmlAttribute: Containing member will be serialized as an XML attribute
  • XmlElement: The field will be serialized as an XML element  
  • XmlIgnore: Field or property will be ignored during Serialization
  • XmlRoot: it represent XML document's root Element
For understanding of above XML attributes, we have changed the Employee type as follows.

[XmlRoot("EmployeeDetail")]
    public class Employee
    {
        public int EmpID{get;set;}
        public string EmpName { get; set; }
        [XmlAttribute("EmployeeType")]
        public string EmpType { get; set; }
        [XmlElement("EmpAddress")]
        public string Address { get; set; }
        [XmlIgnore]
        public double Salary { get; set; }
        public Employee()
        {
            EmpID = 0;
            EmpName = "N/A";
            Address = "N/A";
        }
    }


When you serialize the above code using XML serialization, as we have done before, you will see the XML serialized as follows.




<?xml version="1.0"?>
<EmployeeDetail EmployeeType="Permanent">
  <EmpID>1</EmpID>
  <EmpName>Raj</EmpName>
  <EmpAddress>Pune</Address>
</EmployeeDetail>




XmlRoot:
Every XML has a root element. In XML serialization, the name of the root element is same as the name of the class. XmlRoot attribute is used to provide a custom name to the root element of XML. In the above code the name of the class is Employee and we have used [XmlRoot("EmployeeDetail")] before class declaration. Therefore root element is converted to EmployeeDetail in place of Employee.

XmlElement: 
XmlElement is used for different Tag name in XML. We can use the XmlElement attribute to the class field or property. In the given code xml attribute  [XmlElement("EmpAddress")] is used. So in XML file EmpAddress will be shown in place of Address.

XmlAttribute:
If we want that the property EmpType should displays as the attribute for the Tag EmployeeDetail, then we should use XmlAttribute. As example
EmployeeType="Permanent"

XmlIgnore: 
All the fields and property should be public in XML serialization.
These fields or properties are persisted as an XML element or XML attribute in an XML-file. If you want that some fields should not be shown after XML serialization, then use
XmlIgnore attribute. It will remove the element from the XML as we have done in our example.
[XmlIgnore]
public double Salary { get; set; }


Serialization of DataSet
You can serialize a DataSet object to an XML file. The method for serialization of dataset is same as above but first you have to create dataset and populate with data. We will create a table using DataTable object and then add the table into the DataSet object. We have created the given below table named as Employee. You can create the table according to your need.
 


EmpID
EmpName
Address
1
Raj
Pune
2
Swaraj
USA

using System;
using System.Data;
using System.IO;
using System.Xml.Serialization;
namespace ConsoleApplication1
{
    class Program
    {
        public static void SerializeData()
        {
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(DataSet));
            // Create a DataSet;
            DataSet empDS = new DataSet("emp");
            // Create DataTable.
            DataTable empDT = new DataTable("Employee");
            // Specify columns of a DataTable
            empDT.Columns.Add("EmpID"); //Column1
            empDT.Columns.Add("EmpName"); //Column2
            empDT.Columns.Add("Address"); //Column3
            // Add rows in DataTable
            empDT.Rows.Add("1", "Raj", "Pune");
            empDT.Rows.Add("2", "Swaraj", "USA");
            // Add DataTable in DataSet
            empDS.Tables.Add(empDT);
            // Create an object of stream writer.
            FileStream fs = new FileStream(@"D:\DataSetFile.xml", FileMode.Create);
            // Serialize the instance of BasicSerialization
            xmlSerializer.Serialize(fs, empDS);
            // Close the stream writer
            fs.Close();
        } 
        static void Main(string[] args)
        {
            SerializeData();    
            Console.ReadLine();
        }
    }
}



Run the above application and open the DataSetFile.xml file, you will see the given below output. The XML schema shows all information about the dataset that you have created.

We have filled the dataset using hardcoded values but you can also use database to fill the dataset object.

On the other hand, you could use the DataSet.WriteXml, DataSet.ReadXML, and DataSet.GetXml methods for the same task.

<?xml version="1.0"?>
<DataSet>
  <xs:schema id="emp" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
    <xs:element name="emp" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
      <xs:complexType>
        <xs:choice minOccurs="0" maxOccurs="unbounded">
          <xs:element name="Employee">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="EmpID" type="xs:string" minOccurs="0" />
                <xs:element name="EmpName" type="xs:string" minOccurs="0" />
                <xs:element name="Address" type="xs:string" minOccurs="0" />
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:choice>
      </xs:complexType>
    </xs:element>
  </xs:schema>
  <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
    <emp>
      <Employee diffgr:id="Employee1" msdata:rowOrder="0" diffgr:hasChanges="inserted">
        <EmpID>1</EmpID>
        <EmpName>Raj</EmpName>
        <Address>Pune</Address>
      </Employee>
      <Employee diffgr:id="Employee2" msdata:rowOrder="1" diffgr:hasChanges="inserted">
        <EmpID>2</EmpID>
        <EmpName>Swaraj</EmpName>
        <Address>USA</Address>
      </Employee>
    </emp>
  </diffgr:diffgram>
</DataSet>



What is JSON and JSON Serialization

What is JSON and JSON Serialization

What is JSON?

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write and easy for machines to parse and generate. JSON is a text format that is completely language independent.



JSON supports the following two data structures,
  • Collection of name/value pairs - This Data Structure is supported by different programming languages.
  • Ordered list of values - It includes array, list, vector or sequence etc. 
JSON has following styles,
  1. Object
    An unordered "name/value" assembly. An object begins with "{" and ends with "}". Behind each "name", there is a colon. And comma is used to separate much "name/value". For example,
    1. var user = {"name":"Manas","gender":"Male","birthday":"1987-8-8"}   
  1. Array
    Value order set. An array begins with "[" and end with "]". And values are separated with commas. For example,
    1. var userlist = [{"user":{"name":"Manas","gender":"Male","birthday":"1987-8-8"}},    
    2. {"user":{"name":"Mohapatra","Male":"Female","birthday":"1987-7-7"}}]    
  1. String
    Any quantity Unicode character assembly which is enclosed with quotation marks. It uses backslash to escape.
    1. var userlist = "{\"ID\":1,\"Name\":\"Manas\",\"Address\":\"India\"}"    
We can implement JSON Serialization/Deserialization in the following three ways:
  • Using JavaScriptSerializer class
  • Using DataContractJsonSerializer class
  • Using JSON.NET library 
Using DataContractJsonSerializer

DataContractJsonSerializer class helps to serialize and deserialize JSON. It is present in namespace System.Runtime.Serialization.Json which is available in assembly System.Runtime.Serialization.dll. Using the class we can serialize an object into JSON data and deserialize JSON data into an object.

Let's say there is Employee class with properties such as name, address and property values also assigned. Now we can convert the Employee class instance to JSON document. This JSON document can be deserialized into the Employee class or another class with an equivalent data contract. The following code snippets demonstrate about serialization and deserialization.

Let's create a custom class BlogSite for serialization and deserialization,
  1. [DataContract]  
  2. class BlogSite  
  3. {  
  4.     [DataMember]  
  5.     public string Name { getset; }  
  6.   
  7.     [DataMember]  
  8.     public string Description { getset; }  
  9. }  
Serialization

In Serialization, it converts a custom .Net object to a JSON string. In the following code, it creates an instance of BlogSiteclass and assigns values to its properties. Then we create an instance of DataContractJsonSerializer class by passing the parameter BlogSite class and create an instance of MemoryStream class to write object(BlogSite). Lastly it creates an instance of StreamReader class to read JSON data from MemorySteam object.
  1. BlogSite bsObj = new BlogSite()  
  2. {  
  3.     Name = "C-sharpcorner",  
  4.     Description = "Share Knowledge"  
  5. };  
  6.   
  7. DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(BlogSite));  
  8. MemoryStream msObj = new MemoryStream();  
  9. js.WriteObject(msObj, bsObj);  
  10. msObj.Position = 0;  
  11. StreamReader sr = new StreamReader(msObj);  
  12.   
  13. // "{\"Description\":\"Share Knowledge\",\"Name\":\"C-sharpcorner\"}"  
  14. string json = sr.ReadToEnd();  
  15.   
  16. sr.Close();  
  17. msObj.Close();  
Deserialization

In Deserialization, it does the opposite of Serialization, which means it converts JSON string to a custom .Net object. In the following code, it creates an instance of BlogSite class and assigns values to its properties. Then we create an instance of DataContractJsonSerializer class by passing the parameter BlogSite class and creating an instance of MemoryStream class to write object(BlogSite). Lastly it creates an instance of StreamReader class to read JSON data from MemorySteam object.
  1. string json = "{\"Description\":\"Share Knowledge\",\"Name\":\"C-sharpcorner\"}";  
  2.   
  3. using (var ms = new MemoryStream(Encoding.Unicode.GetBytes(json)))  
  4. {  
  5.    // Deserialization from JSON  
  6.    DataContractJsonSerializer deserializer = new DataContractJsonSerializer(typeof(BlogSite));  
  7.    BlogSite bsObj2 = (BlogSite)deserializer.ReadObject(ms);  
  8.    Response.Write("Name: " + bsObj2.Name); // Name: C-sharpcorner
  9.    Response.Write("Description: " + bsObj2.Description); // Description: Share Knowledge  
  10. }  
  11.    
Using JavaScriptJsonSerializer

JavaScriptSerializer is a class which helps to serialize and deserialize JSON. It is present in namespace System.Web.Script.Serialization which is available in assembly System.Web.Extensions.dll. To serialize a .Net object to JSON string use Serialize method. It's possible to deserialize JSON string to .Net object using Deserialize or DeserializeObject methods. Let's see how to implement serialization and deserialization using JavaScriptSerializer.

Following code snippet is to declare custom class of BlogSites type.
  1. class BlogSites  
  2. {  
  3.     public string Name { getset; }  
  4.     public string Description { getset; }  
  5. }  
Serialization

In Serialization, it converts a custom .Net object to a JSON string. In the following code, it creates an instance of BlogSiteclass and assigns some values to its properties. Then we create an instance of JavaScriptSerializer and call Serialize() method by passing object(BlogSites). It returns JSON data in string format.
  1. // Creating BlogSites object  
  2. BlogSites bsObj = new BlogSites()  
  3. {  
  4.    Name = "C-sharpcorner",  
  5.    Description = "Share Knowledge"  
  6. };  
  7.   
  8. // Serializing object to json data  
  9. JavaScriptSerializer js = new JavaScriptSerializer();  
  10. string jsonData = js.Serialize(bsObj); // {"Name":"C-sharpcorner","Description":"Share Knowledge"}  
Deserialization

In Deserialization, it does the opposite of Serialization which means it converts JSON string to custom .Net object. In the following code, it creates JavaScriptSerializer instance and calls Deserialize() by passing JSON data. It returns custom object (BlogSites) from JSON data.
  1. // Deserializing json data to object  
  2. JavaScriptSerializer js = new JavaScriptSerializer();  
  3. BlogSites blogObject = js.Deserialize(jsonData);  
  4. string name = blogObject.Name;  
  5. string description = blogObject.Description;  
  6.   
  7. // Other way to whithout help of BlogSites class  
  8. dynamic blogObject = js.Deserialize(jsonData);  
  9. string name = blogObject["Name"];  
  10. string description = blogObject["Description"];  
Using Json.NET

Json.NET is a third party library which helps conversion between JSON text and .NET object using the JsonSerializer. The JsonSerializer converts .NET objects into their JSON equivalent text and back again by mapping the .NET object property names to the JSON property names. It is open source software and free for commercial purposes.

The following are some awesome features,
  • Flexible JSON serializer for converting between .NET objects and JSON.
  • LINQ to JSON for manually reading and writing JSON.
  • High performance, faster than .NET's built-in JSON serializers.
  • Easy to read JSON.
  • Convert JSON to and from XML.
  • Supports .NET 2, .NET 3.5, .NET 4, Silverlight and Windows Phone. 
Let’s start learning how to install and implement:

In Visual Studio, go to Tools Menu -> Choose Library Package Manger -> Package Manager Console. It opens a command window where we need to put the following command to install Newtonsoft.Json.

Install-Package Newtonsoft.Json
OR
In Visual Studio, Tools menu -> Manage Nuget Package Manger Solution and type “JSON.NET” to search it online. Here's the figure,

Json.NET

Serialization

In Serialization, it converts a custom .Net object to a Json string. In the following code, it creates an instance of BlogSiteclass and assigns some values to its properties. Then it calls static method SerializeObject() of JsonConvert class by passing object(BlogSites). It returns JSON data in string format.
  1. // Creating BlogSites object  
  2. BlogSites bsObj = new BlogSites()  
  3. {  
  4.     Name = "C-sharpcorner",  
  5.     Description = "Share Knowledge"  
  6. };  
  7.   
  8. // Convert BlogSites object to JOSN string format  
  9. string jsonData = JsonConvert.SerializeObject(bsObj);  
  10.   
  11. Response.Write(jsonData);  
Deserialization

In Deserialization, it does the opposite of Serialization which means it converts JSON string to custom .Net object. In the following code, it calls static method DeserializeObject() of JsonConvert class by passing JSON data. It returns custom object (BlogSites) from JSON data.
  1. string json = @"{  
  2.   'Name''C-sharpcorner',  
  3.   'Description''Share Knowledge'  
  4. }";  
  5.  
  6. BlogSites bsObj = JsonConvert.DeserializeObject(json);  
  7.   
  8. Response.Write(bsObj.Name);  
More on JSON.NET, visit here

Conclusion

In this article we discussed about how many ways we can implement serialization/deserialization in C#. However JSON.NET wins over other implementations because it facilitates more functionality of JSON validation, JSON schema, LINQ to JSON etc. So use JSON.NET always.