I am trying to clean up all designer errors in our solutions and ran into the following error:
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: DoubleAttributeTextBoxBase --- The base class 'NumericAttributeTextBoxBase' could not be loaded. Ensure the assembly has been referenced and that all projects have been built.
The classes are both defined in the same assembly so I know it's not a reference problem. I'm wondering if it has anything to do with the fact that the base class is generic. Any ideas?
public class DoubleAttributeTextBoxBase : NumericAttributeTextBoxBase<double>
public class NumericAttributeTextBoxBase<T> : TextBox where T : IComparable, IComparable<T>
The base class for a class being designed must be non-abstract and non-generic. To make a class that inherits from a generic class designable. The workaround is to insert a trivial non-generic class in-between:
public partial class DoubleAttributeTextBoxBase
: NumericAttributeTextBoxBaseOfDouble
{
public DoubleAttributeTextBoxBase()
{
InitializeComponent();
}
// Now DoubleAttributeTextBoxBase is designable.
}
public class NumericAttributeTextBoxBaseOfDouble
: NumericAttributeTextBoxBase<double>
{
}
To make this as simple as possible, you can even put the non-generic class in the same file as the class you want to design. Just make sure to put it after the class (as I have done above) because the designer expects the first class in the file to be the one being designed.
I don't know of a solution, this has been a severe limitation of Visual studio since C# 2.0 came out. The only thing I can say is to add that control to the page at runtime, then at least you can have your designer back for everything else.
from msdn:
Your component or control cannot be a generic type, which is also called a template type or a parameterized type. The design environment does not support generic types.
http://msdn.microsoft.com/en-us/library/ms171843.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With