views:

618

answers:

1

I am introduction the use of FaultException in to our WCF services.

To test this is I created the following function on the server:

public void ThrowException()
    {
        try
        {
            throw new ApplicationException("This is a test exception");
        }
        catch (ApplicationException ex)
        {
            throw new FaultException<ApplicationException>(ex, "Test reason");

        }
    }

Skipping ahead a step. If I run through this it works fine.

However if I use the debugger (VS2008), and allow the code to break in the catch block (by enabling break on exception, or by stepping in to it), my client generates a CommunicationException.

Investigating this I found this forum post: http://social.msdn.microsoft.com/forums/en-US/wcf/thread/d1ae669f-9a62-4628-86c1-c15ff4068843/

Question: Why am I seeing this behaviour, only when debugging (I assume others are not)? AND how can I avoid this behaviour?

A: 

I wouldn't call this a fix/solution, but I have a workaround well suited to my situation.

As I said I had just started WCF Exception Handling, and I realised IErrorHandler is a better way to handle my exceptions, rather than method-level try/catch.

As the debugger jumps past the implementation of ProvideFault, the debugger doesn't look at the exception, and therefore it doesn't cause a CommunicationException.

This works for now, but I'd still like a real solution, as there may be cases where I want to provide specific exceptions, that will pass untouched through ProvideFault.

MattH