I have a question on how to send a custom exception as FaultException. It works when I use a system Exception like ArgumentException, but if I change it to my custom exception "TestException" it fails. I can’t get the configuration for the service reference, when I try to add it.
Works:
[OperationContract]
[FaultContract(typeof(ArgumentException))]
[TransportChannel TestMethod ();
public Void TestMethod()
{
throw new FaultException<ArgumentException>(new ArgumentException("test"), new FaultReason("test"));
}
Doesn’t work:
[OperationContract]
[FaultContract(typeof(TestException))]
[TransportChannel TestMethod ();
public Void TestMethod()
{
throw new FaultException<TestException>(new TestException("test"), new FaultReason("test"));
}
My “TestException” looks like this:
[Serializable()]
public class TestException: Exception
{
public TestException () : base() { }
public TestException (string message) : base(message) { }
public TestException (string message, Exception innerException) : base(message, innerException) { }
public TestException (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
}
I guess I have to add a DataContract on the custom object, but I don’t understand why it won’t work like it is, since the ArgumentException works. Can someone enlighten me?
Thanks for help :)
[DataContract]
attribute to my custom exception. I was just missing the constructor that tookSerializationInfo
andSerializationContext
. Adding that constructor worked for me. – ChromatographSerialization.StreamingContext
, notSerializationContext
– Godinez