The designer must create an instance of…cannot because the type is declared abstract

前端 未结 3 900
小鲜肉
小鲜肉 2021-02-03 19:32

Visual Studio complains: Warning 1 The designer must create an instance of type \'RentalEase.CustomBindingNavForm\' but it cannot because the type is declared as abst

3条回答
  •  春和景丽
    2021-02-03 20:14

    This worked for me with an abstract class inheriting a UserControl

    public class AbstractCommunicatorProvider : TypeDescriptionProvider
    {
        public AbstractCommunicatorProvider(): base(TypeDescriptor.GetProvider(typeof(UserControl)))
        {
        }
        public override Type GetReflectionType(Type objectType, object instance)
        {
            return typeof(UserControl);
        }
        public override object CreateInstance(IServiceProvider provider, Type objectType, Type[] argTypes, object[] args)
        {
            objectType = typeof(UserControl);
            return base.CreateInstance(provider, objectType, argTypes, args);
        }
    }
    
    
    [TypeDescriptionProvider(typeof(AbstractCommunicatorProvider))]
    public abstract partial class SelectorBase : UserControl
    {
    
    ///class contents 
    }
    

    I didn't need to add this to all derived classes but in your situation you may need to.

提交回复
热议问题