Dealing with SerializationExceptions in C#
        Posted  
        
            by Tony
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Tony
        
        
        
        Published on 2009-09-30T11:51:47Z
        Indexed on 
            2010/03/26
            12:43 UTC
        
        
        Read the original article
        Hit count: 578
        
I get a SerializationException: (...) is not marked as serializable. error in the following code:
[Serializable]
public class Wind
{
    public MyText text;
    public Size MSize;
    public Point MLocation;
    public int MNumber;
    /.../
}
[Serializable]
public class MyText 
{
    public string MString;
    public Font MFont;
    public StringFormat StrFormat;
    public float MySize;
    public Color FColor, SColor, TColor;
    public bool IsRequest;
    public decimal MWide;
    /.../
}
and the List to be serialized:
 List<Wind> MyList = new List<Wind>();
Code Snippet:
 FileStream FS = new FileStream(AppDomain.CurrentDomain.BaseDirectory + 
                                "Sticks.dat", FileMode.Create);
 BinaryFormatter BF = new BinaryFormatter();
 BF.Serialize(FS, MyList);  
 FS.Close();
throws an Exception:
System.Runtime.Serialization.SerializationException was unhandled
  Message="Type 'System.Drawing.StringFormat' in Assembly 'System.Drawing,   
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not 
marked as serializable."
How do I solve this problem?
© Stack Overflow or respective owner