This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Dec 5th, 2011  |  syntax: C#  |  size: 0.62 KB  |  views: 77  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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.  
clone this paste RAW Paste Data