title: Catching multiple custom FaultException types
body: <p>On my WCF service I have a couple of custom fault types. An abstract type called BaseFault and two implementations of it called TypeOneFault and TypeTwoFault</p>
  
  <p>I am throwing the exception on the service side like this</p>
  
  <pre><code>public string ThisMethodHasFault(string eType)
  {
      if (eType.Contains("One"))
      {
          TypeOneFault one = new TypeOneFault("TypeOneFault thrown");
          throw new FaultException&lt;TypeOneFault&gt;(one, new FaultReason(new FaultReasonText("Fault reason here")));
      }
      else
      {
          TypeTwoFault two = new TypeTwoFault("TypeTwoFault thrown");
          throw new FaultException&lt;TypeTwoFault&gt;(two, new FaultReason(new FaultReasonText("Fault reason here")));
      }
  
      return "";
  }
  </code></pre>
  
  <p>My Service interface is like this</p>
  
  <pre><code>[OperationContract]
  [FaultContract(typeof(TypeOneFault ))]
  [FaultContract(typeof(TypeTwoFault ))]
  string ThisMethodHasFault(string eType);
  </code></pre>
  
  <p>On the client side I have a test winform application where I catch it like this</p>
  
  <pre><code>   MyServiceClient client = new MyServiceClient();
  
     try
      {
          client.ThisMethodHasFault(""); //get value from user
  
      }
      catch (FaultException&lt;TypeOneFault&gt;  ox)
      {
           TypeOneFault oneEx = ox.Detail;
           oneEx.{property} ...
  
      }   
      catch (FaultException&lt;TypeTwoFault&gt;  tx)
      {
           TypeTwoFault twoEx = tx.Detail;
           twoEx.{property} ...
      }    
  </code></pre>
  
  <p><strong>Question:</strong></p>
  
  <p>I cant seem to be able to reduce the number of catch blocks by doing this instead</p>
  
  <pre><code>    catch (FaultException&lt;BaseFault&gt; fex)
      {
           BaseFault Ex = fex.Detail;
           twoEx.{property} ...
      }    
  </code></pre>
  
  <p>It would have been nice to have one such block that could capture any exception that I throw on the server and through abstraction I get the right class's details. By doing the above I get an error. <code>An unhandled exception of type 'System.ServiceModel.FaultException</code>1' occurred in mscorlib.dll`</p>
  
  <p><em>Is there something I need to change to make this work or do I have to be content with multiple catch blocks only?</em></p>