Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi guys. I have a windows forms application that uses a User Control to draw some GDI+ shapes. But the thing is, the IDE keeps on displaying an error message that looks like
Code generation for property 'GetShapes' failed: Error was: Type 'SVGFormsApplication.MyShape' in Assembly 'SVGForms Application, Version 1.0.0.0, Culture = neutral, PublicKey Token= null' is not marked as Serializable.'

To make things clear, I am trying to create a list of MyShape objects within the User Control. Here is the source code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace SVGFormsApplication
{
  public partial class DrawingCanvas : UserControl
  {
    private List<MyShape> shapes;
    public DrawingCanvas()
    {
      InitializeComponent();
      shapes = new List<MyShape>(); 
    }
    protected override void OnPaint(PaintEventArgs e)
    {
      base.OnPaint(e);
    }

    public List<MyShape> GetSetShapes // my guess is this part is the culprit
   {
      get
      {
        return shapes;
      }
      set
      {
        shapes = value;
      }
    }

    private void DrawShapes(PaintEventArgs e)
    {
      foreach (MyShape shape in shapes)
      {
        shape.DrawShape(e);
      }
    }

  }
}


I don't personally want to Serialize anything but the error I am getting from the IDE seems to be related with Serialization.
Besides, I have tried to resolve the problem as follows but to no avail.
C#
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public List<MyShape> GetSetShapes
{
    get
    {
        return shapes;
    }
    set
    {
        shapes = value;
    }
}


Thanks in advance for any reply.
Posted
Updated 18-Nov-10 6:30am
v2
Comments
Amin ra 19-Oct-12 8:40am    
I have Same Problem. need Help
panahi.ehsan 3-Feb-16 5:40am    
Thanks, your solution solve my problem...

You are getting an error on "GetShapes", not "GetSetShapes", you may want to try adding the serialization visibility attribute to the private member as well. (Just a shot in the dark on something that jumped out at me, BTW)
 
Share this answer
 
Comments
Bezawit 17-Nov-10 8:56am    
Thanks for the reply PogoboyKramer. But I have tried that too to no avail. This is the wirdest thing I encountered in my programming carrier? Btw, did u ever get a solution to this problem?
Bezawit 17-Nov-10 9:06am    
Btw, things worked just fine after I restarted the IDE. May be, re-compiling was not enough after adding the attributes!WoW!
xirisjohn 9-May-11 17:37pm    
You definitely have to restart the IDE. I've seen this before.
I think that you are getting this error because VS is trying to create the 'whatever.designer.cs' file and is encountering the problem at that point.

Is your MyShape marked as serializable?
 
Share this answer
 
Hey Guys exact problem is mine,, Please do help... I need the solution.... urgent.
 
Share this answer
 
Problem solved on stackOverflow

Worked for me
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900