SearchError
から継承するクラスがException
あり、有効なjsonから逆シリアル化しようとすると、次の例外が発生します。
ISerializableタイプ'SearchError'には有効なコンストラクターがありません。ISerializableを正しく実装するには、SerializationInfoパラメーターとStreamingContextパラメーターを受け取るコンストラクターが存在する必要があります。パス''、行1、位置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コードでも):
メンバー「ClassName」が見つかりませんでした。
また、この関連する質問と同じソリューションを実装しようとしましたが、上記と同じエラーが発生しました。