:Azureサービスバスで例外をシリアル化する方法は?私は、応答キューにWebJobの実行の結果として例外を送信しようとしている
var message = new BrokeredMessage(exception);
outputMessages.Add(message);
私の例外クラスは、論理的なエラーを表します。
public class MyException : Exception{
public MyException(){}
public MyException(string message) : base(message){}
public MyException(string message, Exception inner) : base(message, inner){}
protected MyException(SerializationInfo info, StreamingContext context) : base(info, context){}
public object MyProp { get; set; }
}
はしかし、私は次の取得します例外:私は[DataContract]
でMyException
をマークするとき
Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: Functions.ProcessQueueMessage2Async ---> System.Runtime.Serialization.InvalidDataContractException: Type 'MyException' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute. See the Microsoft .NET Framework documentation for other supported types.
そして、私はこれを取得:
Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: Functions.ProcessQueueMessage2Async ---> System.Runtime.Serialization.InvalidDataContractException: Type 'MyException' cannot be ISerializable and have DataContractAttribute attribute.
おそらくSystem.Exception
がISerializable
を実装しているためです。どうすれば修正できますか?
"応答[...]を応答キューに送信する" - 受信者は本当にException *オブジェクト全体を必要としますか?あるいは、 '.ToString()'やステータスコード、またはカスタムメッセージパケットを使うほうが良いでしょうか? – AakashM
UIのエラーメッセージを適切にフォーマットするために追加の情報(私の例ではMyProp)を渡す必要があるので、私は文字列や列挙型を使うことができません。 – UserControl