IncludeExceptionDetailInFaults not behaving as thought

Posted by pdiddy on Stack Overflow See other posts from Stack Overflow or by pdiddy
Published on 2010-04-01T15:14:59Z Indexed on 2010/04/01 15:23 UTC
Read the original article Hit count: 460

Filed under:
|
|
|

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?

© Stack Overflow or respective owner

Related posts about wcf

Related posts about exception-handling