Showing posts from June, 2014

The uncatchable exceptions in WCF clients

Did you ever have a problem with a WCF client throwing exceptions you can't catch? If you have used WCF clients from Windows Phone, Silverlight or Xamarin.iOS, you might have noticed that it is not possible to create Synchronous or Task-Based operations; the functionality is reduced to the Event-based Asynchronous Pattern (EAP). That means that the way to call a WCF method and get the response is usually as follows: var client = new MyWCFClient(); client.DownloadDataCompleted += (sender, e) => { try { //accessing e.Result here might raise an exception in another //thread, that will not be captured by the 'catch' below. } catch(Exception ex) { } }; client.DownloadDataAsync(url); Our results are wrapped in an auto-generated class that inherits from  AsyncCompletedEventArgs , this class has a property  Error  of type  Exception , that will carry information about the error and a property  Result  with our expected return value. Accessing th