SHARE
TWEET

Untitled

a guest Dec 5th, 2011 87 Never
  1. Stream stream = null;
  2. try
  3. {
  4.     plugin.Initialize(); //plugin is IPlugin instance created with Activator.CreateInstance
  5.  
  6.     stream = File.Open("serialized.txt", FileMode.Create);
  7.     BinaryFormatter formatter = new BinaryFormatter();
  8.  
  9.     formatter.Serialize(stream, plugin); //Successful
  10.     stream.Close();
  11.  
  12.     stream = File.Open("serialized.txt", FileMode.Open);
  13.     BinaryFormatter formatter2 = new BinaryFormatter();
  14.  
  15.     object obj = formatter2.Deserialize(stream); //Fails
  16.  
  17.     this.Text = obj.GetType().ToString();
  18. }
  19. catch (Exception ex)
  20. {
  21.     this.Text = ex.Message;
  22. }
  23. finally
  24. {
  25.     stream.Close();
  26. }
  27.  
RAW Paste Data
Top