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:
However, my forms application had been built to handle the exception as follows:
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.: