locked
Serializable control problem. RRS feed

  • Question

  • Hi
    i've created a some controls :
    1. DayControl which inherit from Panel control
    2. WeekControl which hold a collection of days and also this inherits from Panel control.

    The dayControl works good and i can add it to my form without any problem, but when i drag & drop WeekControl to my form, i got this big error message:

    Microsoft Visual Studio
    ---------------------------
    Failed to create component 'WeekControl'.  The error message follows:
    
     'System.Runtime.Serialization.SerializationException: Type 'System.Windows.Forms.Panel' in Assembly 'System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable.
    
       at System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type)
    
       at System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context)
    
       at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo()
    
       at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter)
    
       at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter)
    
       at System.Runtime.Serialization...'
    ---------------------------
    OK

    i added Serializable attribute at the begining of my WeekControl class definition, but the problem was not solved.
    where is my problem and how to solve it ?
    thanks in advance.
    http://www.codeproject.com/KB/codegen/DatabaseHelper.aspx
    Wednesday, February 10, 2010 1:24 PM

Answers

  • Sorry. 
    Forms and their controls are not serializable. 
    Forget about it.

    Define a custom class that describes the state of the form/control.
    A class that would, of course, be serializable.

    Rudy  =8^D

    Mark the best replies as answers. "Fooling computers since 1971."
    • Marked as answer by liurong luo Tuesday, February 16, 2010 11:06 AM
    Wednesday, February 10, 2010 2:25 PM

All replies

  • Sorry. 
    Forms and their controls are not serializable. 
    Forget about it.

    Define a custom class that describes the state of the form/control.
    A class that would, of course, be serializable.

    Rudy  =8^D

    Mark the best replies as answers. "Fooling computers since 1971."
    • Marked as answer by liurong luo Tuesday, February 16, 2010 11:06 AM
    Wednesday, February 10, 2010 2:25 PM
  • Sorry. 
    Forms and their controls are not serializable. 
    Forget about it.

    Define a custom class that describes the state of the form/control.
    A class that would, of course, be serializable.

    Rudy  =8^D

    Mark the best replies as answers. "Fooling computers since 1971."

    Thanks Rudy
    can u give me more information ?
    what u mean about 'Define a custom class that describes the state of the form/control' ?
    http://www.codeproject.com/KB/codegen/DatabaseHelper.aspx
    Wednesday, February 10, 2010 9:25 PM