我想创建UserControl的子类:
public class BaseUserControl : UserControl
{
// Add some useful, common functions..
public void CommonFunction()
{
}
}
但是,当我尝试在我设计的控件中使用这个基类时,如下所示:
public partial class NewPanel : BaseUserControl
{
}
我得到错误自定义属性签名中不支持的类型参数当我试图查看控件(下面提供的调用堆栈)时,Visual Studio设计器中的异常。如果我将子类恢复到UserControl
,那么一切都很好。
为了记录,上面的例子不是完整的代码,但是我试着注释掉BaseUserControl
的内部,我仍然得到这个消息。
有谁知道这意味着什么以及如何排除故障和/或解决它吗?
谢谢。
调用堆栈:
at Microsoft.MetadataReader.SignatureUtil.GetTypeId(Type type)
at Microsoft.MetadataReader.MetadataOnlyModule.GetConstructorArguments(ConstructorInfo constructorInfo, Byte[] customAttributeBlob, Int32& index)
at Microsoft.MetadataReader.MetadataOnlyModule.LazyAttributeParse(Token token, ConstructorInfo constructorInfo, IList`1& constructorArguments, IList`1& namedArguments)
at Microsoft.MetadataReader.MetadataOnlyCustomAttributeData.get_ConstructorArguments()
at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkUtil.ConstructAttribute(CustomAttributeData data)
at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkUtil.GetCustomAttributes(ICustomAttributesDataProvider member, Type filter, CustomAttributesCache cache)
at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkUtil.GetCustomAttributes(Type type, Type filter, Boolean inherit, CustomAttributesCache cache)
at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkUtil.GetCustomAttributes(Type type, Type filter, Boolean inherit, CustomAttributesCache cache)
at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkAttributeCollection.GetAttributes(Type type, Type filter)
at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkAttributeCollection.get_Attributes()
at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkAttributeCollection.get_Attributes()
at System.ComponentModel.MemberDescriptor..ctor(MemberDescriptor oldMemberDescriptor, Attribute[] newAttributes)
at System.ComponentModel.Design.InheritedPropertyDescriptor..ctor(PropertyDescriptor propertyDescriptor, Object component, Boolean rootComponent)
at System.ComponentModel.Design.ComponentDesigner.InitializeInheritedProperties(Boolean rootComponent)
at System.ComponentModel.Design.ComponentDesigner.Initialize(IComponent component)
at System.Windows.Forms.Design.ControlDesigner.Initialize(IComponent component)
at System.Windows.Forms.Design.ParentControlDesigner.Initialize(IComponent component)
at System.Windows.Forms.Design.DocumentDesigner.Initialize(IComponent component)
at System.ComponentModel.Design.DesignerHost.AddToContainerPostProcess(IComponent component, String name, IContainer containerToAddTo)
at System.ComponentModel.Design.DesignerHost.PerformAdd(IComponent component, String name)
at System.ComponentModel.Design.DesignerHost.System.ComponentModel.Design.IDesignerHost.CreateComponent(Type componentType, String name)
at System.ComponentModel.Design.Serialization.DesignerSerializationManager.CreateInstance(Type type, ICollection arguments, String name, Boolean addToContainer)
at System.ComponentModel.Design.Serialization.DesignerSerializationManager.System.ComponentModel.Design.Serialization.IDesignerSerializationManager.CreateInstance(Type type, ICollection arguments, String name, Boolean addToContainer)
at System.ComponentModel.Design.Serialization.TypeCodeDomSerializer.Deserialize(IDesignerSerializationManager manager, CodeTypeDeclaration declaration)
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.DeferredLoadHandler.Microsoft.VisualStudio.TextManager.Interop.IVsTextBufferDataEvents.OnLoadCompleted(Int32 fReload)
与命名类(BaseUserControl)的冲突/歧义相关的问题。一旦我发现了BaseUserControl的重复类,并确保没有歧义(即删除不必要的'using'语句),问题就解决了。