views:

366

answers:

1

Hi, 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

+7  A: 

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.

tster
Thank you very much, you were right.
AlbertEin
I can confirm that this workaround works. And it works whether you put the intermediate class (e.g. GenericInt) in assembly **A** or assembly **B**.
Kyralessa