title: How to Serialize & Deserialize Exception Objects Without any Data Loss?
body: <p>I am trying to serialize and store Exception objects to a file and then retrieve it back by deserializing.</p>
  
  <pre><code>File.Delete(_FilePath);
  using (Stream stream = File.Open(_FilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite))
  {
      new BinaryFormatter().Serialize(stream, originalException);
  }
  
  using (Stream stream = File.Open(_FilePath, FileMode.Open, FileAccess.Read))
  {
       Exception deserializedException = (Exception)(new BinaryFormatter().Deserialize(stream));
     // deserializedException.TargetSite is null!!!
  }
  </code></pre>
  
  <p>However, the deserialized Exception object's TargetSite property is null. i.e., it doesn't get serialized as a result of which it isn't getting deserialized as well. The TargetSite property is of type MethodBase. (Serializing MethodBase doesn't make sense IMO)</p>
  
  <p>Is there any other way of storing and retrieving full Exception object without any data loss?</p>