Thoughts on Integrating Systems & IoT

WCF Error from Visual Studio Debugger: “An exception of type ‘System.ServiceModel.FaultException`1’ occurred but was not handled in user code”

This error got me stumped for a bit…  The solution was quite simple but caused a few further grey hairs so I will share here how I resolved this annoyance!

I was hosting a WCF solution in Visual Studio (for testing and debugging purposes) and calling it from a forms application.  Things were going well until I introduced typed SOAP faults: I wanted to throw a typed fault from my WCF solution and for my forms application to catch and handle the error.

When I threw the error from my WCF solution, the Visual Studio debugger complained, saying that the error was unhandled:

Visual Studio 2013 SOAP Fault Unhandled Error

Fig. 1  Visual Studio 2013 SOAP Fault Unhandled Error

However, my forms application had been built to handle the exception as follows:

But SOAP Fault Handled in my Forms App

Fig. 2  But SOAP Fault Handled in my Forms App

I couldn’t work out for sometime how to suppress the error but then noticed a check box in the VS exception message box: “Break when this exception type is user-unhandled” (highlighted in Fig. 1 above).

The wording is a bit of misnomer since I am actually handling the error in my forms app but I guess the VS debugger can’t work this out.  I unchecked the box and VS behaved as I wanted it to: my WCF solution was able to throw the exception for handling by my forms app.

I later learnt that it also possible to configure how the VS debugger behaves in regards to exceptions by selecting “DEBUG –> Exceptions…”.  This opens an exceptions windows where it is possible to configure if the debugger should break or not for certain exception types e.g.:

Specify if Debugger should Break

Fig. 3  Specified that the Debugger should not Break for Exceptions of Type ‘System.ServiceModel.FaultException`1’



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s