WCF Exception Shielding - hides inner exception?

Topics: Exception Handling Application Block
May 2, 2007 at 3:36 AM
I'm having a problem with the WCF Exception Shielding in the EntLib 3.0 Exception Handling block - it seems like whatever exceptions fall into the Fault Contract Exception Handler get converted to type Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.FaultContractWrapperException, with no InnerException. In my case I'm throwing an exception with useful debugging info in the Data property. The fault handler produces the right fault contract, but by the time the exception gets to the logging handler it's been converted to FaultContractWrapperException and the Data is gone so there's nothing useful to log.

Is there some way to use the WCF Exception Shielding and still get to see the underlying exception details in the logging handler?

May 3, 2007 at 2:05 AM
I haven't used this feature yet, but according to the documentation it sounds like you need to map properties that you want to be carried over from the original exception.

Per the Documentation:

Using the Fault Contract Exception Handler

When using the Exception Handling Application Block for exception shielding in WCF applications, you can use the Fault Contract Exception Handler to convert a runtime exception to an appropriate Fault Contract type. This exception handler also enables you to map properties from the original exception and the Handling Instance Id to properties in the Fault Contract.

To use the Fault Contract Exception Handler

- Create an exception handling policy that includes the appropriate exception types for your application. For more information, see Entering Configuration Information.

- Configure the exception type, specifying the PostHandlingAction as ThrowNewException. This means that the application block throws the new exception that has been created by wrapping the original exception. The throw occurs after the entire chain of handlers runs.
- Add a new Fault Contract Exception Handler for the specified exception types.
- Configure the Fault Contract Exception Handler:
Specify the desired Fault Contract Type that should be returned to the client

Add the exception message to be used in the Fault Contract returned to the client

Optionally, configure how properties from the original exception will be mapped to the Fault Contract. In the FaultContractPropertyMapping Editor dialog, add an item for each property you wish to map. The Name property refers to a property name on the Fault Contract. The Source property specifies the name of the property on the original exception from which the value should be retrieved. You can also specify a Source of “{Guid}” to add the current Handling Instance Id to the Fault Contract property.

The Fault Contract Exception Handler will automatically map any properties from the exception to the Fault Contract if their names match and their types are compatible. If you wish to prevent this, you can add a mapping with a Name of the Fault Contract property name and a Source with an empty string.




David Hayden
Microsoft MVP C#
May 3, 2007 at 3:28 AM
I think I've figured out what the problem was - the order of the exception handlers in the config seems to be critical. I had the Fault Contract handler first, before the logging handler. Switched the order and now the logging handler sees the original exception.