Bug 2981 - WCF: Cannot catch System.ServiceModel.FaultException
Summary: WCF: Cannot catch System.ServiceModel.FaultException
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 5.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2012-01-20 04:54 UTC by René Ruppert
Modified: 2017-09-08 01:05 UTC (History)
5 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description René Ruppert 2012-01-20 04:54:26 UTC
MT 5.1.2, iOS5 Simulator

One of the calls to my services raises a System.ServiceModel.FaultException:

{System.ServiceModel.FaultException`1[System.ServiceModel.ExceptionDetail]: Exception of type 'Brainloop.Exceptions.DRDataroomNotFoundException' was thrown. (Fault Detail is equal to Exception of type 'Brainloop.Exceptions.DRDataroomNotFoundException' was thrown.).}

My call is surrounded by a try-catch that catches Exception but exceptions generated through WCF will never be caught.
See bug #2843 for a demo project (button "FaultException").
The exception is raised in ClientRuntimeChannel.Process(), l. 485 by an explicit throw and that's where execution stops. It will not reach my catch.

public object Process (MethodBase method, string operationName, object [] parameters)
			var previousContext = OperationContext.Current;
			try {
				// Inherit the context from the calling thread
				if (this.context != null) 
					OperationContext.Current = this.context;

				return DoProcess (method, operationName, parameters);
			} catch (Exception ex) {
#if MOONLIGHT // just for debugging
				Console.Write ("Exception in async operation: ");
				Console.WriteLine (ex);
			} finally {
				// Reset the context before the thread goes back into the pool
				OperationContext.Current = previousContext;
Comment 1 Rolf Bjarne Kvinge [MSFT] 2012-02-06 05:48:23 UTC
Is this also fixed if the test case prints this?

! GetTree() error: DATAROOM_NOT_FOUND, Exception of type
'Brainloop.Exceptions.DRDataroomNotFoundException' was thrown.
Comment 2 René Ruppert 2012-02-06 06:35:47 UTC
I assume so. The problem was that the exception handling code has never been reached because
 it failed to deserialize the exception.
Comment 3 Rolf Bjarne Kvinge [MSFT] 2012-02-06 06:42:08 UTC
OK, this is fixed too then, thanks.
Comment 4 Ryan Alford 2012-07-04 11:27:33 UTC
I am running across this same issue in MonoTouch 5.2.12.  I have also tried it in MonoTouch 5.3.4.

Our WCF web service throws an exception when some data is incorrect.  In a normal .Net application, when this method is called asynchronously, the exception is passed back in the AsyncCompletedEventArgs' Error property in the Completed event.

In MonoTouch, it throws the exception.  The problem with this is that we can't catch the exception.  It crashes the application.  I have put a breakpoint in the Completed event for the method, but the breakpoint never gets hit.  The exception is thrown before the WCF code executes the Completed event.

Is there a chance that it can be fixed to behave like .Net?  There is already an Error property on the AsyncCompletedEventArgs class, it's just not being used.
Comment 5 Rolf Bjarne Kvinge [MSFT] 2012-07-04 11:43:24 UTC
Ryan, as far as I know WCF behaves as .Net in this regard, so I'd need a complete sample to see what's going wrong in order to track down any issues.
Comment 6 Melbourne Developer 2017-09-08 01:05:00 UTC
We are having this same problem in the latest version of Xamarin (Mono) for Android. We cannot catch a FaultException thrown from our WCF services while this does work in UWP. I am looking for the simplest possible sample app so we can report the problem to the Xamarin team. Is there a sample app floating around anywhere?