Hi,
I'm trying to throw my own custom exception inside a FaultException from my WCF service and catch it in my WCF client. On the client side, however, the exception is caught as a non-generic FaultException and the details of my custom exception are lost.
My custom exception is:
[Serializable] public class MyCustomException : ApplicationException
{ ... }
Here's how I throw it:
throw new FaultException<MyCustomException>(new MyCustomException("foo bar!"));
(Note that I do have a [FaultContract(typeof(MyCustomException))] placed over my method in the interface)
And here's how I try to catch it in my client:
...
catch (FaultException<MyCustomException> mcex)
{
Console.WriteLine(mcex);
}
catch (FaultException fex)
{
Console.WriteLine(fex);
}
My goal is for the exception to be caught in the first catch clause above, but it ends up caught in the second catch clause.
The curious thing is that if I replace MyCustomException with ApplicationException then indeed FaultException is properly caught.
I'm guessing the problem is that MyCustomException is serialized a Serializable (and not via the DataContractSerializer) and that maybe I'm missing some additional directive to WCF. Something in the line of a ServiceKnownType attribute? (Though I tried that, to no avail).