title: WCF FaultContract Fails with NamedPipe
body: <p>I have a simple IPC mechanism that uses WCF and named pipes.  My goal is to propagate exception details (including the stacktrace) to the client for logging purposes (the rest of the application logging is located on the client).</p>
  
  <p>If I use the following code I am able to catch FaultException&lt;Exception&gt; on the client and see exception details:</p>
  
  <p>Contract:</p>
  
  <pre><code>[ServiceContract]
  public interface IService
  {
      [OperationContract]
      [FaultContract(typeof(Exception))]
      void DoSomething();
  }
  </code></pre>
  
  <p>Implementation:</p>
  
  <pre><code>public class Service : IService
  {
      public void DoSomething()
      {
          try
          {
              ThisWillThrowAnException();
          }
          catch (Exception e)
          {
              throw new FaultException&lt;Exception&gt;(e);
          }
      }
   }
  </code></pre>
  
  <p>Client:</p>
  
  <pre><code>public void CallServer()
  {
      try
      {
          proxy.DoSomething();
      }
      catch (FaultException&lt;Exception&gt; e)
      {
          Console.WriteLine("Caught fault exception!");
      }
  }
  </code></pre>
  
  <p>This works fine and I see the message printed on the console.  However, if I want to use my own derived exception instead of the base Exception class, it fails.</p>
  
  <p>Custom Exception:</p>
  
  <pre><code>[Serializable]
  public class MyException : Exception
  {
      public MyException () { }
      public MyException (string message) : base(message) { }
      public MyException (string message, Exception inner) : base(message, inner) { }
      protected MyException (
        SerializationInfo info,
        StreamingContext context)
          : base(info, context) { }
  }
  </code></pre>
  
  <p>Change the FaultContract on IService.DoSomething to </p>
  
  <pre><code>typeof(MyException).
  </code></pre>
  
  <p>Change the throw clause in Service to</p>
  
  <pre><code>new FaultException&lt;MyException&gt;(new MyException(e.Message, e);
  </code></pre>
  
  <p>Change the catch clause in the client to</p>
  
  <pre><code>catch (FaultException&lt;MyException&gt; e)
  </code></pre>
  
  <p>When I execute this, a CommunicationException is caught on the client with the error:
  <em>System.ServiceModel.CommunicationException: There was an error reading from the pipe: The pipe has been ended. (109, 0x6d).</em></p>
  
  <p>The MyException class is in a shared library available to both the client and server.</p>
  
  <p>This question is very similar to <a href="https://stackoverflow.com/questions/220401/how-do-you-configure-wcf-to-support-faultcontracts-where-both-the-host-and-client">this question</a>, but that did not help me.</p>