I have this simple test project just to test the IncludeExceptionDetailInFaults behavior.
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 the app.config of the service i have it 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);
}
This is what I thought the behavior was: Setting to includeExceptionDetailInFaults=true would propagate the exception detail to the client. But I'm always getting the CommunicationObjectFaultException.
I did try having the FaultContract(typeof(InvalidCastException)) on the contract but same behavior, only getting the CommunicationObjectFaultException.
The only way to make it work was to throw new FaultException(new InvalidCastException("test"));
But I thought with IncludeExceptionDetailInFaults=true the above was done automatically.
Am I missing something?