Home > Net >  Subclassing UserControl gives "Unsupported type argument" error
Subclassing UserControl gives "Unsupported type argument" error

Time:07-11

I am trying to subclass UserControl like so:

public class BaseUserControl : UserControl
{
  // Add some useful, common functions..
  public void CommonFunction()
  {
  }
}

However, when I try to use this base class in my designed control like so:

public partial class NewPanel : BaseUserControl
{
}

I get the error Unsupported type argument in custom attribute signature exception in the Visual Studio Designer when I try to view the control (Call stack provided below). If I revert the subclass back to UserControl, then everything is fine again.

For the record, the example above is not the full code, however I have tried to comment out the internals of BaseUserControl and I still get this message.

Does anyone know what this means and how to troubleshoot and/or solve it?

Thanks.

Call stack:

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) 

CodePudding user response:

The issue related to a clash/ambiguity of the named class (BaseUserControl). Once I found the duplicate class of BaseUserControl and made sure that there was no ambiguity (i.e. removed unnecessary 'using' statements), the problem was resolved.

  • Related