Mam klasy SearchError
która dziedziczy Exception
, a kiedy tylko próbuję deserializowania ją z ważnego json pojawia się następujący wyjątek:Json.net nie powiedzie się podczas próby deserializacji klasy, która dziedziczy z Exception
ISerializable type 'SearchError' does not have a valid constructor. To correctly implement ISerializable a constructor that takes SerializationInfo and StreamingContext parameters should be present. Path '', line 1, position 81.
Próbowałem implementacji sugerowanego brakującego konstruktora, a to nie pomogło.
Jest to klasa po wdrożeniu zaproponowanej konstruktora:
public class APIError : Exception
{
[JsonProperty("error")]
public string Error { get; set; }
[JsonProperty("@http_status_code")]
public int HttpStatusCode { get; set; }
[JsonProperty("warnings")]
public List<string> Warnings { get; set; }
public APIError(string error, int httpStatusCode, List<string> warnings) : base(error)
{
this.Error = error;
this.HttpStatusCode = httpStatusCode;
this.Warnings = warnings;
}
public APIError(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
: base(info, context)
{
Error = (string)info.GetValue("error", typeof(string));
HttpStatusCode = (int)info.GetValue("@http_status_code", typeof(int));
Warnings = (List<string>)info.GetValue("warnings", typeof(List<string>));
}
}
Teraz dostaję następujący wyjątek (również w kodzie Json.NET):
Member 'ClassName' was not found.
Próbowałem też wdrażającego takie samo rozwiązanie jak w przypadku this related question, również otrzymałem ten sam błąd powyżej.
Podziel kod z ludźmi .. –
To pytanie zostało tutaj odpowiedział: http://stackoverflow.com/a/3423037/504836 – joelnet