title: What is the correct way to make a custom .NET Exception serializable?
body: <p>More specifically, when the exception contains custom objects which may or may not themselves be serializable.</p>
  
  <p>Take this example:</p>
  
  <pre><code>public class MyException : Exception
  {
      private readonly string resourceName;
      private readonly IList&lt;string&gt; validationErrors;
  
      public MyException(string resourceName, IList&lt;string&gt; validationErrors)
      {
          this.resourceName = resourceName;
          this.validationErrors = validationErrors;
      }
  
      public string ResourceName
      {
          get { return this.resourceName; }
      }
  
      public IList&lt;string&gt; ValidationErrors
      {
          get { return this.validationErrors; }
      }
  }
  </code></pre>
  
  <p>If this Exception is serialized and de-serialized, the two custom properties (<code>ResourceName</code> and <code>ValidationErrors</code>) will not be preserved. The properties will return <code>null</code>.</p>
  
  <p><strong>Is there a common code pattern for implementing serialization for custom exception?</strong></p>