繼承的類我有一個類SearchError
從Exception
繼承和失敗時當過我嘗試從一個有效的JSON我得到下面的異常反序列化:Json.net嘗試反序列化,從異常
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.
我試圖實現建議缺少的構造函數,並沒有幫助。
這是落實建議的構造後級:
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>));
}
}
現在我收到以下異常(也json.net代碼):
Member 'ClassName' was not found.
我也試過實施與this related question相同的解決方案,也得到了上述相同的錯誤。
分享您與人代碼.. –
這個問題已經在這裏找到答案:http://stackoverflow.com/a/3423037/504836 – joelnet