I'm trying to send an exception as a result of a WebJob execution to a response queue:
var message = new BrokeredMessage(exception);
outputMessages.Add(message);
My exception class represents a logical error:
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; }
}
However, I get the following exception:
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.
And when I mark MyException
with [DataContract]
I get this:
Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: Functions.ProcessQueueMessage2Async ---> System.Runtime.Serialization.InvalidDataContractException: Type 'MyException' cannot be ISerializable and have DataContractAttribute attribute.
Probably because System.Exception
implements ISerializable
. How can I fix that?
.ToString()
, or a status code, or some custom message packet? – AakashMMyProp
in my example) to properly format error messages on UI. – UserControl