I have this simple test project to test the behavior of IncludeExceptionDetailInFaults.
public class Service1 : IService1 { public string GetData(int value) { throw new InvalidCastException("test"); return string.Format("You entered: {0}", value); } } [ServiceContract] public interface IService1 { [OperationContract] string GetData(int value); }
In app.config service I set to true
<serviceDebug includeExceptionDetailInFaults="True" />
On the client side:
try { using (var proxy = new ServiceReference1.Service1Client()) Console.WriteLine(proxy.GetData(5)); } catch (Exception ex) { Console.WriteLine(ex.Message); }
Here's what I thought about what it was: Setting to enableExceptionDetailInFaults = true will propagate the exception details to the client. But I always get CommunicationObjectFaultException exception.
I tried using FaultContract (typeof (InvalidCastException)) in the contract, but the same behavior, only getting a CommunicationObjectFaultException.
The only way to make it work is to throw a new FaultException (new InvalidCastException ("test"));
But I thought that with IncludeExceptionDetailInFaults = true this was done automatically.
Am I missing something?
source share