Json.net fails when trying to deserialize a class that inherits from Exception

This question has been answered here: https://stackoverflow.com/a/3423037/504836

Adding a new constructor

public Error(SerializationInfo info, StreamingContext context){}

solved my problem.

Here complete code:

[Serializable]
public class Error : Exception
{

    public string ErrorMessage { get; set; }

    public Error(SerializationInfo info, StreamingContext context) {
        if (info != null)
            this.ErrorMessage = info.GetString("ErrorMessage");
    }
    public override void GetObjectData(SerializationInfo info,StreamingContext context)
    {
        base.GetObjectData(info, context);

        if (info != null)
            info.AddValue("ErrorMessage", this.ErrorMessage);
    }
}

As the error says, you are missing the serialization constructor:

public class SearchError : Exception
{
    public SearchError(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context)
    {

    }
}

Tags:

C#

Json

Json.Net