none
Code generation for property <xxx> failed

    General discussion

  •  

    Hi everybody,

    When trying to edit or even just save a winform in my application I get the following exception (several times):

     

    "Code generation for property 'notchChanged' failed. Error was:'Type TimeSpanControl in Assembly... is not marked as serializable'.

     

    The TimeSpanControl is an inherent of windows UserControl. I tried to mark it as serializable but it didn't do the job.

    Does anyone have a clue?

     

    BTW: I use .NET 2.0 (Visual C# 2005)

     

    thanks,

    James.

    Wednesday, November 21, 2007 12:40 PM

All replies

  • In order to be serializable a type must use the Serializable attribute and/or implement ISerializable.  Additionally all fields must be serializable or marked with the NonSerialized attribute.  Check your class to ensure this is true.  If you can't figure it out then post the relevant class and field definitions and we might be able to help you more.

     

    Michael Taylor - 11/21/07

    http://p3net.mvps.org

     

    Wednesday, November 21, 2007 3:22 PM
    Moderator
  • The thing is, I do not need my class to be serializable (does it have to be?!). Tried to make it serializable anyway and still got the same error.

    The weirdest thing is that it pops up this error whenever I try to work with the designer opened, even though it manages to show the designed form. Actually I can say that beside the fact that it annoys, the error has no implications whatsoever on the building or running the application.

     

    ?

    Thursday, November 22, 2007 8:29 AM
  • Hi tsiki,

     

    As I underastand, you can try to follow Michael's suggestions and post the relevant class and field definitions source codes here. You'd better add some comments to your sample codes and clarify which code lines may cause this error message. In this way, you can get more helps from this community members from MSDN forums Thanks.. 

     

    Regards,

    Friday, November 23, 2007 3:35 AM
    Moderator
  • Did you ever find a resolution for this problem?  I've got the same issue.

    Tuesday, May 20, 2008 2:47 PM
  • I've got the same problem. Does anyone have a solution?
    Thursday, August 28, 2008 3:26 PM
  • I had the same problem.

            private List<MyItem> myItems;

            public List<MyItem> MyItems
                {
                get { return myItems; }
                set { myItems = value; }
                }

    I ereased the property and made the variable public:

            public List<MyItem> MyItems;

    //        public List<MyItem> MyItems
    //            {
    //            get { return myItems; }
    //            set { myItems = value; }
    //            }

    But it didn't help. The message still appeared no matter what kind of action I did and after dosens of stupid message boxes the whole application were buildable and runned properly.

    I closed the solution, restarted the dev-env, rebuilt it again and... it worked great!

    Then I restored the old code, but without 'set' accessor for List<> variable this time and it's ok now.

            private List<MyItem> myItems;

            public List<MyItem> MyItems
                {
                get { return myItems; }
                }







    Tofas
    Monday, September 29, 2008 11:04 AM
  • Designer automatically tries to serialize all public UserControl properties. Try telling serializer not to do this if this property is not needed for your custom UserControl desing-time support. Add "DesignerSerializationVisibility" attribute:

    private List<MyItem> myItems;

    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
    public List<MyItem> MyItems
    {
      get { return myItems; }
      set { myItems = value; }
    }

    This helped me.
    Thursday, August 13, 2009 7:03 AM
  • Justinas had a key point that helped us fix this - by making the List private, the problem went away.
    Friday, September 18, 2009 5:53 PM
  • I'm making a calendar application (using http://windowsclient.net/downloads/folders/applications/entry1340.aspx) and adding [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] to the list of calendar items helped me:

    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
    public List<CalendarItem> CalendarItems
    {
    get
    {
    return m_items;
    }
    set
    {
    m_items = value;
    }
    }

    Thanks Justinas!

    Monday, March 19, 2012 2:48 PM