Click or drag to resize
Json.NETConstructorHandling setting
 

This sample uses the ConstructorHandling setting to successfully deserialize the class using its non-public constructor.

Sample
Types
 1public class Website
 2{
 3    public string Url { get; set; }
 4
 5    private Website()
 6    {
 7    }
 8
 9    public Website(Website website)
10    {
11        if (website == null)
12        {
13            throw new ArgumentNullException(nameof(website));
14        }
15
16        Url = website.Url;
17    }
18}
Usage
 1string json = @"{'Url':'http://www.google.com'}";
 2
 3try
 4{
 5    JsonConvert.DeserializeObject<Website>(json);
 6}
 7catch (Exception ex)
 8{
 9    Console.WriteLine(ex.Message);
10    // Value cannot be null.
11    // Parameter name: website
12}
13
14Website website = JsonConvert.DeserializeObject<Website>(json, new JsonSerializerSettings
15{
16    ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor
17});
18
19Console.WriteLine(website.Url);
20// http://www.google.com