Here's what I observe
I need to throw a custom Exception subtype from the service to the client. (Listed as a FaultContract on the specific operation). I have certain fields on the CustomException, that should be received by the client.
[Serializable]
class MyCustomException : Exception
{
public string From { get; private set; }
public MyCustomException(string where)
{
From = where;
}
}
}
I find that the field isn't being deserialized even though the exception is present inside the FaultException instance. I tried implementing ISerializable by overriding GetObjectData and the serialization ctor, but no dice. The only way I could get it across was changing MyCustomException to be a DataContract and not derive from Exception.
[DataContract]
class MyCustomException
{
[DataMember]
public string From { get; private set; }
public MyCustomException(string where)
{
From = where;
}
}
This works. However it can't be derived from Exception anymore.. since Exception is marked with the Serializable attribute and you can't have both Serializable and DataContract on a type. (Confirmed: run time Exception thrown)
So my question is : What is the right way to propogate the fields of a custom exception subtype in WCF?