I had a problem in my program in the part where I am loading a serialized file. I want to succeed if the file cannot be deserialized, but for some reason my program will break and not go into the catch clause. Here is my code
using (FileStream fs = new FileStream(openFileDialog1.FileName, FileMode.Open)) { try { BinaryFormatter bf = new BinaryFormatter(); document = (Document)bf.Deserialize(fs); } catch (SerializationException se) { MessageBox.Show("Error opening this file due to serialization", se.Source); } catch (Exception se) { MessageBox.Show("Error opening this file due to serialization", se.Source); } }
Running this causes the program to break into the Deserialize () line. This is an exception:
Type 'Source' in Assembly 'DocumentDesigner, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.
I know how to fix the exception because I commented out a couple of [Serializable] attributes to check this out, but I just want to know why the try clause doesn't work.
source share