locked
UserControl not marked as serializable RRS feed

  • Question

  • Hello,

    I have a 2 projects in a C++ solution. First project has a form with user control. User control class (deriving from UserControl,  has  [Serializable] attribute; its List<Byte> private field has [NonSerialized]) is in second DLL project. When I build any project, the error message is following: Code generation for property 'Tag' failed. Error was: 'Type'System.Windows.Forms.UserControl; in Assembly 'System.Windows.Forms,Version=2.0.0.0, Culture=neutral, PublicKeyToken=...' is not marked as serializable.' It appears 2 times. When I click OK after last message, the compilation starts.

    How can I get rid of it?

    Sunday, February 19, 2012 4:18 PM

Answers

  • The UserControl class is not serializable, meaning no controls derived from UserControl can be serializable.  If you are trying to serialize your user control, you are out of luck.

    Jose R. MCP

    • Proposed as answer by Bob Wu-MT Tuesday, February 21, 2012 7:54 AM
    • Marked as answer by Bob Wu-MT Thursday, March 8, 2012 3:29 AM
    Monday, February 20, 2012 2:20 AM

All replies

  • The UserControl class is not serializable, meaning no controls derived from UserControl can be serializable.  If you are trying to serialize your user control, you are out of luck.

    Jose R. MCP

    • Proposed as answer by Bob Wu-MT Tuesday, February 21, 2012 7:54 AM
    • Marked as answer by Bob Wu-MT Thursday, March 8, 2012 3:29 AM
    Monday, February 20, 2012 2:20 AM
  • Hi px2195,
    You can know whether the Type is serializable by using Type.IsSerializable Property and typeof(UserControl).IsSerializable return false which means that it is not Serializable.
    Could you please tell us why do you trying to make your custom control serializable, maybe we can find other way out?
    Best Regards,


    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, February 21, 2012 7:54 AM
  • > Could you please tell us why do you trying to make your custom control serializable, maybe we can find other way out?

    Hi, I am trying to make custom control serializable because of error message box generated by Visual Studio 2008 Windows Forms Editor, about which I wrote above. I must still click 'OK' to continue working in VS. I have tested system with antivirus.

    Wednesday, February 22, 2012 3:25 PM
  • Remove the [Serializable] attribute from the user control.

    Jose R. MCP

    Wednesday, February 22, 2012 3:28 PM
  • Hi px2195,
    I understand that the visual studio will give this error message when you mark it as with the SerializableAttributeattribute. But why you want to mark the custom control with the SerializableAttributeattribute?
    If you want to serialize the property of the custom control at design time, then you should read the following two articles,
    http://msdn.microsoft.com/en-us/library/ms171834.aspx
    http://msdn.microsoft.com/en-us/library/ms171833.aspx
    Best Regards,

    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, February 23, 2012 3:15 AM
  • Is the UserControl marked as public?
    Do you have Serialization Assemblies being generated (by default)?

    IIRC, the serialization assembly tries to support serializing anything public in the project even if there is no other, practical reason for doing so. Unless you really need them, I would turn off the creation of serialization assemblies (in the project properties).


    Regards, Phill W.

    Thursday, February 23, 2012 1:42 PM
  • That doesn't answer the question.

    I have the same thing happening.  Suddenly visual studio complains that some control is not serializable, so you mark it as such, then it complains that whatever that inherits from isn't serializable...all the way up to UserControl.

    So why does Visual Studio want my components to be serializable?

    Wednesday, November 26, 2014 7:37 PM
  • And the real answer is that the control I was trying to drop on the form had a public property that was a list<T>, which is not serializable.  This had to be marked to be not included in the designer properties:

           

    [Browsable(false)]        

    [EditorBrowsable(EditorBrowsableState.Never)]

    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]    

        public List<itemT> items        { ...}


    Wednesday, November 26, 2014 7:58 PM