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

匿名 (未验证) 提交于 2019-12-03 02:44:02

问题:

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 : 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 {     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

回答1:

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 : UserControl { } 

then

class GenericInt : Generic { } 

then use GenericInt instead of Generic. SUcks I know.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!