Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2008 Winform designer fails to load Form which inherits from generic class

i have a winforms project, and i created a class on assembly A that inherits from System.Windows.Forms.Form to serve as a base class for various forms on my project, the base class is something like:

public partial class DataForm<T> : Form where T : class
{

    T currentRecord;

    protected T CurrentRecord
    {
        get
        {
            return currentRecord;
        }
        set
        {
            currentRecord = value;
            CurrentRecordChanged();
        }
    }
}

Now, when i create a form on assembly B that inherits from my DataForm the designer won't load, but if i compile it the app runs fine.

The form looks like:

public partial class SomeTableWindow : DataForm<SomeTable>
{
    public SomeTableWindow ()
    {
        InitializeComponent();
    }
}

The error I'm getting is:

The designer could not be shown for this file because none of the classes within it can be designed. 
The designer inspected the following classes in the file: CultivosWindow --- The base
class 'TripleH.Erp.Controls.DataForm' could not be loaded. Ensure the assembly has 
been referenced and that all projects have been built.    


Instances of this error (1)  

1.   Hide Call Stack 

at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.EnsureDocument(IDesignerSerializationManager manager)
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
at System.ComponentModel.Design.Serialization.BasicDesignerLoader.BeginLoad(IDesignerLoaderHost host)  

Is this a bug on the designer?, Am I doing something wrong? Is there some workaround this?

Thank you for your help

like image 375
albertein Avatar asked Jan 12 '10 18:01

albertein


1 Answers

It's a known limitation. Basically you can work around this by declaring another class that inherits from the generic class.

For instance:

class Generic<T> : UserControl
{
}

then

class GenericInt : Generic<int> { }

then use GenericInt instead of Generic. SUcks I know.

like image 69
tster Avatar answered Sep 19 '22 21:09

tster