title: Proper way to throw exception over WCF
body: <p>I'm trying to send exceptions over WCF in the most generic way possible. Here's what I've got:</p>
  
  <pre><code>[ServiceContract]
  interface IContract
  {
      [OperationContract]
      void Foo();
  }
  
  class ContractImplementation: IContract
  {
      public void Foo()
      {
          try
          {
              Bar();
          }
          catch (Exception ex)
          {
              throw new FaultException&lt;Exception&gt;(ex, ex.Message);
          }
      }
  }
  </code></pre>
  
  <p>The exception that is actually coming out of <code>Bar</code> is:</p>
  
  <pre><code>[Serializable]
  class MyException : Exception
  {
      // serialization constructors
  }
  </code></pre>
  
  <p>The error I'm seeing in the server-side WCF logging is:</p>
  
  <blockquote>
    <p>Type 'MyException' with data
    contract name
    'MyException:<a href="http://schemas.datacontract.org/2004/07/MyException">http://schemas.datacontract.org/2004/07/MyException</a>'
    is not expected. Consider using a DataContractResolver or add any
    types not known statically to the list of known types - for example,
    by using the KnownTypeAttribute attribute or by adding them to the
    list of known types passed to DataContractSerializer.</p>
  </blockquote>
  
  <p>What I've tried so far:</p>
  
  <pre><code>[ServiceKnownType(typeof(MyException))]
  [ServiceContract]
  interface IContract
  {
      [FaultContract(typeof(MyException))]
      [OperationContract]
      void Foo();
  }
  </code></pre>
  
  <p>But no luck.</p>