Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Form Designer Does Not Display Form Containing Custom Control with Generics
 

Form Designer Does Not Display Form Containing Custom Control with Generics

I have a form the gives me the following error when I try to design it in Visual Studio 2005:

One or more errors encountered while loading the designer. The errors are listed below. Some errors can be fixed by rebuilding your project, while others may require code changes.

Unable to load type System.Collections.Generic.List`1[[fcPhotoGallUpload.keywordManeger+ListItem, KeywordMan, Version=1.0.2235.34332, Culture=neutral, PublicKeyToken=null]] required for deserialization.

Hide

at System.Runtime.Serialization.ObjectManager.DoFixups()
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)
at System.Resources.ResXDataNode.GenerateObjectFromDataNodeInfo(DataNodeInfo dataNodeInfo, ITypeResolutionService typeResolver)
at System.Resources.ResXDataNode.GetValue(ITypeResolutionService typeResolver)
at System.Resources.ResXResourceReader.ParseDataNode(XmlTextReader reader, Boolean isMetaData)
at System.Resources.ResXResourceReader.ParseXml(XmlTextReader reader)


It containsa custom control that exposes a generic list as apublic property.

The list is container for my custom type:


        [Serializable()]
        public class ListItem : IComparable, System.Runtime.Serialization.ISerializable
     {
            public int intId;
            public string Display;

            public ListItem()
            {
            }

            //Constructor for serialization
            protected ListItem(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
            {
                this.intId = info.GetInt32("intID");
                this.Display = info.GetString("Display");
            }
            public override string ToString()
            {
                return Display;
            }
            
            public static explicit operator ListItem(DataRowView Data)
            {
                ListItem Item = new ListItem();
                Item.intId = (int)Data.Row.ItemArray[0];
                Item.Display = (string)Data.Row.ItemArray[1];
                return Item;
            }

            #region IComparable Members

            public int CompareTo(object obj)
            {
                if (((ListItem)obj).intId == this.intId &&
                    ((ListItem)obj).Display.CompareTo(this.Display) == 0)
                    return 0;
                else
                    return this.Display.CompareTo(((ListItem)obj).Display);
            }

            #endregion


            #region ISerializable Members
            [System.Security.Permissions.SecurityPermission(
                System.Security.Permissions.SecurityAction.Demand,
                SerializationFormatter = false)]
            public void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
            {
                info.AddValue("Display", this.Display);
                info.AddValue("intID", this.intId);
            }

I have been trying to figure this out for a while.

Any help on this problem will be greatly appreciated.

Ephraim Shurpin  Tuesday, February 21, 2006 8:52 PM

I am postingwhat I did to solve this problemin order that others who had the same problem will know what to do.

I deletedthe followinglines from .designer.cs file with a text editor.

this.kymMain.Events = ((System.Collections.Generic.List<fcPhotoGallUpload.keywordManeger.ListItem>)(resources.GetObject("kymMain.Events")));

this.kymMain.Keywords = ((System.Collections.Generic.List<fcPhotoGallUpload.keywordManeger.ListItem>)(resources.GetObject("kymMain.Keywords")));

this.kymMain.People = ((System.Collections.Generic.List<fcPhotoGallUpload.keywordManeger.ListItem>)(resources.GetObject("kymMain.People")));

this.kymMain.Programs = ((System.Collections.Generic.List<fcPhotoGallUpload.keywordManeger.ListItem>)(resources.GetObject("kymMain.Programs")));

I then added back the set accessors,deleted the user control dll, removed the refrences to it, saved the solution,closed Visual Studio, reopened it, rebuilt it, closed it again, reopened it andadded back the refrence. Now it appears in the designer properly.


Ephraim Shurpin

Ephraim Shurpin  Friday, March 17, 2006 5:12 PM

Hello,

Is the assembly that contains your custom control strongly named? I am running into the same problem and it only occurred after I added a strong name to the assembly. I think I may know why too... Whenever I alter the class library that has the custom control then I have to manually remove all references to the control from other projects and readd it to get it to work and I think its because they are referencing the control from a library that no longer exists (since the version info changes) so it can't deserialize the Type needed. I think if you add the "Delay sign only" attribute to the library with your custom control then you can get around this while debugging, until you are ready to deploy. I"m not sure about this entirely but I think I'm on the right track here.

Justin Chase  Thursday, March 30, 2006 5:10 PM

Try setting designerserializationvisibility on the List<> property. As in:

public class MyU : UserControl
{
private List<ListItem> myList = new List<ListItem>();

public MyU()
{
myList.Add(new ListItem(1,"1"));
myList.Add(new ListItem(2, "2"));
}

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public List<ListItem> MyList
{
get { return myList; }
}
}

[Serializable()]
public class ListItem
{
public int intId;
public string Display;

public ListItem(int x, string y)
{
intId = x;
Display = y;
}
}

Which should result in code spit like:

this.myU1.MyList.Add(((WindowsApplication152.ListItem)(resources.GetObject("myU1.MyList"))));

this.myU1.MyList.Add(((WindowsApplication152.ListItem)(resources.GetObject("myU1.MyList1"))));

which hopefully will work better.

Benjamin Wulfe - MS  Wednesday, February 22, 2006 2:33 AM

I added the [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
attribute to the properties and it still does not appear in the designer.

As for the code spit this is what it was before and after I added the attribute.

this.kymMain.Events = ((System.Collections.Generic.List<fcPhotoGallUpload.keywordManeger.ListItem>)(resources.GetObject("kymMain.Events")));

this.kymMain.Keywords = ((System.Collections.Generic.List<fcPhotoGallUpload.keywordManeger.ListItem>)(resources.GetObject("kymMain.Keywords")));

this.kymMain.Location = new System.Drawing.Point(3, 66);

this.kymMain.Name = "kymMain";

this.kymMain.People = ((System.Collections.Generic.List<fcPhotoGallUpload.keywordManeger.ListItem>)(resources.GetObject("kymMain.People")));

this.kymMain.Programs = ((System.Collections.Generic.List<fcPhotoGallUpload.keywordManeger.ListItem>)(resources.GetObject("kymMain.Programs")));


Ephraim Shurpin
Ephraim Shurpin  Wednesday, February 22, 2006 5:45 PM

It looks like you may not have added the attribute correctly. Can you try my sample to see if it works correctly?

Remember to remove the "set" property accessor from your properties as well.

Benjamin Wulfe - MS  Friday, February 24, 2006 6:24 PM

I tried using your sample and it still did not affect the code that was already in the designer.cs file.

I also took off the set accessors, temporarily, as I will need set accessors. However, it still did not affect the code.

Thanks for your effort so far.


Ephraim

Ephraim Shurpin  Friday, February 24, 2006 7:19 PM
I ran into the same problem today, and couldn't get rid of it anymore. I also tried the suggestions in this forum, but that didn't help either. It is strange that I removed the generic list from my control and I still get the same message. So, I guess something is buffered and I don't know how to clear it. Any idea?
miliu  Monday, March 06, 2006 3:25 AM

Have you tried to open the form and modify it to force a new serialization to occur?

If you can try it on a new form to ensure it works, then the problem is only updating older forms.

Also, if you can do a full rebuild -- then close and reopen VS2005, that may also fix the issue. Sorry for this problem.

Benjamin Wulfe - MS  Monday, March 06, 2006 3:32 AM

I am postingwhat I did to solve this problemin order that others who had the same problem will know what to do.

I deletedthe followinglines from .designer.cs file with a text editor.

this.kymMain.Events = ((System.Collections.Generic.List<fcPhotoGallUpload.keywordManeger.ListItem>)(resources.GetObject("kymMain.Events")));

this.kymMain.Keywords = ((System.Collections.Generic.List<fcPhotoGallUpload.keywordManeger.ListItem>)(resources.GetObject("kymMain.Keywords")));

this.kymMain.People = ((System.Collections.Generic.List<fcPhotoGallUpload.keywordManeger.ListItem>)(resources.GetObject("kymMain.People")));

this.kymMain.Programs = ((System.Collections.Generic.List<fcPhotoGallUpload.keywordManeger.ListItem>)(resources.GetObject("kymMain.Programs")));

I then added back the set accessors,deleted the user control dll, removed the refrences to it, saved the solution,closed Visual Studio, reopened it, rebuilt it, closed it again, reopened it andadded back the refrence. Now it appears in the designer properly.


Ephraim Shurpin

Ephraim Shurpin  Friday, March 17, 2006 5:12 PM

Hello,

Is the assembly that contains your custom control strongly named? I am running into the same problem and it only occurred after I added a strong name to the assembly. I think I may know why too... Whenever I alter the class library that has the custom control then I have to manually remove all references to the control from other projects and readd it to get it to work and I think its because they are referencing the control from a library that no longer exists (since the version info changes) so it can't deserialize the Type needed. I think if you add the "Delay sign only" attribute to the library with your custom control then you can get around this while debugging, until you are ready to deploy. I"m not sure about this entirely but I think I'm on the right track here.

Justin Chase  Thursday, March 30, 2006 5:10 PM

This is not a dependable solution because next time you add another instance of that control to the page, it happens again.

Here is my code :

[LookupBindingProperties("DataSource", "DisplayMember", "ValueMember", "SelectedValue")]
public partial class BaseLookupControl : BaseUserControl
{
public BaseLookupControl()
{
InitializeComponent();
}

private string myDisplayMember;
[DefaultValue("")]
public string DisplayMember
{
get { return myDisplayMember; }
set
{
myDisplayMember = value;
OnDisplayMemberChanged(new EventArgs());
}
}

public event EventHandler DisplayMemberChanged;

protected virtual void OnDisplayMemberChanged(EventArgs e)
{
if (DisplayMemberChanged != null)
{
DisplayMemberChanged(this, e);
}
}

private string myValueMember;
[DefaultValue("")]
public string ValueMember
{
get { return myValueMember; }
set
{
myValueMember = value;
OnValueMemberChanged(new EventArgs());
}
}

public event EventHandler ValueMemberChanged;

protected virtual void OnValueMemberChanged(EventArgs e)
{
if (ValueMemberChanged != null)
{
ValueMemberChanged(this, e);
}
}

private object myDataSource;
[DefaultValue("")]
[AttributeProvider(typeof(IListSource))]
[RefreshProperties(RefreshProperties.All)]
public object DataSource
{
get { return myDataSource; }
set
{
myDataSource = value;
OnDataSourceChanged(new EventArgs());
}
}

public event EventHandler DataSourceChanged;

protected virtual void OnDataSourceChanged(EventArgs e)
{
if (DataSourceChanged != null)
{
DataSourceChanged(this, e);
}
}

private string myDataMember;

[RefreshProperties(RefreshProperties.All)]
[Editor("System.Windows.Forms.Design.DataMemberListEditor, System.Design", "System.Drawing.Design.UITypeEditor, System.Drawing")]
[DefaultValue("")]
public string DataMember
{
get { return myDataMember; }
set
{
myDataMember = value;
OnDataMemberChanged(new EventArgs());
}
}

public event EventHandler DataMemberChanged;

protected virtual void OnDataMemberChanged(EventArgs e)
{
if (DataMemberChanged != null)
{
DataMemberChanged(this, e);
}
}

private string mySelectedValue;
public event EventHandler SelectedValueChanged;

[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[Browsable(false)]
[Bindable(true)]
[DefaultValue("")]
public string SelectedValue
{
get { return mySelectedValue; }
set
{
mySelectedValue = value;
OnSelectedValueChanged(new EventArgs());
}
}

protected virtual void OnSelectedValueChanged(EventArgs e)
{
if (SelectedValueChanged !=null)
{
SelectedValueChanged(this, e);
}
}

private void BaseLookupControl_Load(object sender, EventArgs e)
{
}

}

I have copied most of it from the Meta information of "LISTBOX" control.

Listbox does not have "DesignerSerializationVisibility.Hidden" or "DesignerSerializationVisibility.Content" attribute on the Datasource property.

However, when I drop this control on my form I get "DataSource of controlxyz is null. This is not allowed" error message (Yes, a popup error message on the designer).

Even if I set the DataSource of this control to a dataset on my form, that error keeps popping up.

If I add an attribute "DesignerSerializationVisibility.Content" or "DesignerSerializationVisibility.Hidden", then the designer does not gererate code in the designer file. I tried BOTH of the settings, yields the same result. I was expecting it to WRITE CODE i nthe designer file with the "CONTENT" setting, but not serialize it in the resX file...

Can you please give a clear description of the designer serialization attribute values, and the designer.cs (or vb for that matter) and resx behavior ?

Please correct me if I am wrong: on http://msdn2.microsoft.com/en-us/library/system.componentmodel.designerserializationvisibility.aspxit says

Member name Description
Content The code generator produces code for the contents of the object, rather than for the object itself.
Hidden The code generator does not produce code for the object.
Visible The code generator produces code for the object.

There is NOTHING about the serialization in the resX file there...

But I assume "rather than the object itself" means "the object will not be serialized in the RESX file" there.

Please suggest

durayakar  Thursday, March 30, 2006 6:50 PM

My assemblies are also strongly named, but my base control and the derived controls are in the same library, i moved them together, still no luck...

durayakar  Thursday, March 30, 2006 7:17 PM

Try to write designer for your control like that:

class YourControlDesigner : System.Windows.Forms.Design.ControlDesigner
{
public YourControlDesigner()
{ }

protected override void PostFilterProperties(System.Collections.IDictionary properties)
{
properties.Remove("YourGenegicPropertyName");
}
}

And You should type that code before declaration of your control

[Designer(typeof(YourControlDesigner))]
public partial class YourControl : UserControl
{
}

It works for me, may be one helps you.

sotona  Wednesday, October 25, 2006 11:26 AM
Yes, my assembly is strongly named, and what you wrote about the version numbers makes sense. Since I changed the control not to be strongly named it has not given me any problems.
Thanks for the insight.
Ephraim Shurpin  Friday, March 09, 2007 4:52 PM

ANSWER:

All you have to do is justdelete the .resx file for the form that the custom control resides on. Re-open the form in the designer and make your changes and re-compile. Sometimes the problem goes away and sometime it comes back.

-ratster

ratster  Thursday, March 22, 2007 2:41 PM
ratster wrote:

ANSWER:

All you have to do is justdelete the .resx file for the form that the custom control resides on. Re-open the form in the designer and make your changes and re-compile. Sometimes the problem goes away and sometime it comes back.

-ratster

I'm afraid that's not the solution...
After removing the resx file, designer is showing me a NullReference exception.

Object reference not set to an instance of an object.
Hide

at System.ComponentModel.ReflectPropertyDescriptor.SetValue(Object component, Object value)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializePropertyAssignStatement(IDesignerSerializationManager manager, CodeAssignStatement statement, CodePropertyReferenceExpression propertyReferenceEx, Boolean reportError)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeAssignStatement(IDesignerSerializationManager manager, CodeAssignStatement statement)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager manager, CodeStatement statement)
Kenny Clement  Friday, September 12, 2008 7:21 AM
Hello I had the same problem

In my case I had

loged into an old version of my product
upgraded my product
opened a new tab in my browser
opened thenew version of my product

All I had to do to solve the problem was close the browser and open it again

Thanks

John
John Winstanley  Monday, July 06, 2009 3:24 PM
Hi,

I had the same problem too with a form embedded control which has public generic list properties.
Strange behaviour: sometimes i can open a form, somtimes not.

For me the tag
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
helped for one form. I too deleted all initializer with type/null value for the problematic properties in the .Designer.cs

But for another form the problem still existed.
But finally I found a solution for me:

I opened the Designer.resx for the form and found a remaining entry for the control with a type entry.
I deleted that entry and now i can open the form without problems.

Maybe this will be another approach for a solution.

Best regards
Martin
  • Proposed As Answer bydcomer Monday, August 17, 2009 4:45 PM
  •  
designmode  Friday, July 24, 2009 10:12 AM

You can use google to search for other answers

Custom Search

More Threads

• Controls Disappearing vs 2k5 Professional
• Gah! The designer is filling in my properties for me!!
• AcceptButton like property
• Could not find 'WindowsApplication1.Program'
• how to setfocus in VS .NET?
• ToolStripRenderer
• ZOrder
• Clone control properties
• Error message "Type SqlAddapter is not defined"
• How to draw border of a pop-up menu