This project has moved and is read-only. For the latest updates, please go here.


Protected ctor does not get called


In the example below, why does the public ctor get picked instead of the default protected ctor?
This will fail because of this - it will succeed if the default ctor gets picked

void Main()

public class Tagged : Tag
    protected Tagged() : base() { }

    public Tagged(Tag tagDefinition)
        Id = tagDefinition.Id;
public abstract class Tag
    public int Id { get; set; }
Closed Jan 30, 2013 at 11:09 AM by JamesNK
Because Json.NET defaults to using public. Read the documentation if you want to see how to change that.


georgiosd wrote Feb 13, 2013 at 7:34 PM

The only thing I could find in the docs is JsonConstructor which only allows to do it on a per-object basis.

I'd like JSON.NET to use the default ctor in all cases, regardless of its visibility - is this possible to specify?

georgiosd wrote Feb 13, 2013 at 7:36 PM

Never mind, just found ConstructorHandling.AllowNonPublicDefaultConstructor

wrote Feb 22, 2013 at 2:47 AM

wrote May 16, 2013 at 1:36 PM