none
The given assembly name or codebase was invalid Windows Forms

    Question

  • I am getting "The given assembly name or codebase was invalid" Error when I open the windows forms designer in VS 2010. The project I am working on is very large so I created a new project and worked then problem down to then minimum code nessassay to reproduce the problem.

    Stack Trace:

    at System.Reflection.AssemblyName.nInit(RuntimeAssembly& assembly, Boolean forIntrospection, Boolean raiseResolveEvent)
    at System.Reflection.AssemblyName..ctor(String assemblyName)
    at Microsoft.VisualStudio.Design.VSTypeResolutionService.System.ComponentModel.Design.ITypeResolutionService.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase)
    at Microsoft.VisualStudio.Design.VSTypeResolutionService.System.ComponentModel.Design.ITypeResolutionService.GetType(String name, Boolean throwOnError)
    at Microsoft.VisualStudio.Design.Serialization.CodeDom.HandlesClauseManager.GetReferencedComponentType(String componentName, CodeTypeDeclaration codeTypeDecl, ITypeResolutionService loader, IDictionary& cache)
    at Microsoft.VisualStudio.Design.Serialization.CodeDom.HandlesClauseManager.ParseHandlesClauses(CodeTypeDeclaration codeTypeDecl, Boolean updateCache)
    at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomParser.OnMethodPopulateStatements(Object sender, EventArgs e)
    at System.CodeDom.CodeMemberMethod.get_Statements()
    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) 
      

    Here is the Code to reproduce:

    Interface: I1.vb

    Public Interface I1
      Event MyEvent()
    End Interface

     

    UserControl: UC1.vb

    Public Class UC1
      Implements I1
      Public Event MyEvent() Implements I1.MyEvent
      Private Sub UC1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      End Sub
    End Class

     

    Class: Class1.vb

    Imports System.windows.forms
    Public Class Class1(Of typUserControl1 As {UserControl, New}, typUserControl2 As {UserControl, New}, typUserControl3 As {UserControl, New}) '
      Inherits Panel
      Public Event SomeEvent(ByRef sender As Object, ByVal args As EventArgs)
    End Class

     

    Form: Form1.vb

    Public Class Form1
      Protected WithEvents oNewPanel As New Class1(Of UC1, UC1, UC1)
      Private Sub oNewPanel_SomeEvent(ByRef sender As Object, ByVal args As EventArgs) Handles oNewPanel.SomeEvent
      End Sub
    End Class
    • Moved by Ji.Zhou Friday, August 06, 2010 9:58 AM (From:Visual Basic IDE)
    Thursday, August 05, 2010 5:02 PM

Answers

  • Or

    I can just live with the designer window error as I will not be using it to design the class as it is a control based class not form based.

    If I create a regular class with no inheritance and double click the Class.vb file it opens straight to the code window.  Is it possible through an attribute or some other means to have Class2 open directly to code, and/or eliminate the designer thus solving the whole “Type.ContainsGenericParameters is true” error issue all together?

    	[System.ComponentModel.DesignerCategory("")]
    	public partial class Form1 : Form
    	{
    		 // ...
    	}
    


    This will open code view directly when you click on the file .. you'll notice that the icon in the sln explorer gets changed too.


    best regards,
    Vladimir
    • Marked as answer by Karl Grear Tuesday, August 10, 2010 7:56 PM
    Tuesday, August 10, 2010 7:33 PM
  • I also figured out that by leaving the withevents out and using Addhandler corrected the issue.

     

    I did want some designer functionality however.  The original project was to create a reusable MSAccess like continuous forms engine, where the first 2 custom controls were the header and data row gui elements.  At the end of the day I was hoping to be able to go to my toolbox and drag the continuous form (class1) to my designer, set the generic parameters and display the header and 1 data row element at design time. 

     

    But as it turns out, neither the form designer nor the toolbox play nice with generics.

     

    Here is what I came up with so far.

     

    I derived a second class (Class2) from Class1 supplying the generic types.  This is not as neat but it allows me to display the continous form in the toolbox and on the form in design mode.

     

     Oddly I am now getting a new error on the Class2 designer:
     Cannot create an instance of Class1`3[typUserControl1,typUserControl2,typUserControl3] because Type.ContainsGenericParameters is true.

     

     What’s odd is that: GetType(Class2).ContainsGenericParameters returns false when I test it from code

     

     I have not figured this one out yet, but the code does compile, and Class2 can be dragged from the toolbox and does display the custom controls at design time on form1

    Any more thoughts?

    Imports System.windows.forms
    Public Class Class1(Of typUserControl1 As {UserControl, New}, typUserControl2 As {UserControl, New}, typUserControl3 As {UserControl, New}) '
     Inherits Panel
     Public Event SomeEvent(ByRef sender As Object, ByVal args As EventArgs)
    
    Protected Overrides Sub InitLayout()
      If Me.DesignMode = True Then
       Me.Controls.Clear()
       Dim tmpH As New UC1
       Me.Controls.Add(tmpH)
       tmpH.Visible = True
       tmpH.Top = 0
       tmpH.Left = 0
       Dim tmpR As New UC1
       Me.Controls.Add(tmpR)
       tmpR.Visible = True
       tmpR.Top = tmpH.Height + 1
       tmpR.Left = 0
       MyBase.InitLayout()
       MyBase.OnCreateControl()
      End If
      MyBase.InitLayout()
     End Sub
    
    End Class
    
    <System.ComponentModel.ToolboxItem(True)> _
    Public Class Class2
     Inherits Class1(Of UC1, UC1, UC1)
    End Class

      

     

    • Marked as answer by Karl Grear Tuesday, August 10, 2010 7:56 PM
    Tuesday, August 10, 2010 4:13 PM
  • OK,

    Class1 is derived from the System.Windows.Forms.Panel class
    Class2 is derived from Class1

    Because the Panel class is non generic I can double click on the Class1.vb file and our friendly neighborhood ‘To add components to your class’ designer pops up just fine.

    But because,  Class1 is generic when you double click the Class2.vb file you will receive the “Type.ContainsGenericParameters is true” error

    However if I create a third and otherwise useless class Class3 derived from Class2, and placed it in the top of the Class2.vb file, I can then double click the Class2.vb file and see the ‘To add components’ designer window which is actually displaying the designer for Class3 not Class2.

    Or

    I can just live with the designer window error as I will not be using it to design the class as it is a control based class not form based.

    If I create a regular class with no inheritance and double click the Class.vb file it opens straight to the code window.  Is it possible through an attribute or some other means to have Class2 open directly to code, and/or eliminate the designer thus solving the whole “Type.ContainsGenericParameters is true” error issue all together?

    • Marked as answer by Karl Grear Tuesday, August 10, 2010 7:55 PM
    Tuesday, August 10, 2010 6:57 PM

All replies

  • Hello Karl,

    I'm a c# guy so I don't know what exactly is happening here but this is what I got:

    I have first narrowed it down a little bit more by deleting UC1 class and changing Fom1 to 

     

    Public Class Form1
    
     Protected WithEvents oNewPanel As New Class1(Of UserControl, UserControl, UserControl)
     'Protected WithEvents oNewPanel As New Class1(Of UC1, UC1, UC1)
    
     Private Sub oNewPanel_SomeEvent(ByRef sender As Object, ByVal args As EventArgs) Handles oNewPanel.SomeEvent
     End Sub
    
    End Class
    

     

    and I got the same error.

    So i figured the error might be in the event handler, when the designer tries to hook it up. I changed it a little bit more and made the error disappear. Since the code in constructor does not get executed in design time I moved subscribing to event to the form constructor. 

    Do you need the event to be handled in design time ?

    EDIT: Well, even when I derived Form2 from Form1, which means that Form1 constructor gets executed in design time for Form2, the error did not reappear.

     

    Public Class Form1
    
     Protected WithEvents oNewPanel As New Class1(Of UserControl, UserControl, UserControl)
     'Protected WithEvents oNewPanel As New Class1(Of UC1, UC1, UC1)
    
     Public Sub New()
    
      ' This call is required by the Windows Form Designer.
      InitializeComponent()
    
      ' Add any initialization after the InitializeComponent() call.
      AddHandler oNewPanel.SomeEvent, AddressOf Me.oNewPanel_SomeEvent
    
     End Sub
    
     Private Sub oNewPanel_SomeEvent(ByRef sender As Object, ByVal args As EventArgs) 'Handles oNewPanel.SomeEvent
     End Sub
    
    End Class
    

     

    Hope this helps, 

    best regards,
    Vladimir

    Friday, August 06, 2010 5:06 PM
  • I also figured out that by leaving the withevents out and using Addhandler corrected the issue.

     

    I did want some designer functionality however.  The original project was to create a reusable MSAccess like continuous forms engine, where the first 2 custom controls were the header and data row gui elements.  At the end of the day I was hoping to be able to go to my toolbox and drag the continuous form (class1) to my designer, set the generic parameters and display the header and 1 data row element at design time. 

     

    But as it turns out, neither the form designer nor the toolbox play nice with generics.

     

    Here is what I came up with so far.

     

    I derived a second class (Class2) from Class1 supplying the generic types.  This is not as neat but it allows me to display the continous form in the toolbox and on the form in design mode.

     

     Oddly I am now getting a new error on the Class2 designer:
     Cannot create an instance of Class1`3[typUserControl1,typUserControl2,typUserControl3] because Type.ContainsGenericParameters is true.

     

     What’s odd is that: GetType(Class2).ContainsGenericParameters returns false when I test it from code

     

     I have not figured this one out yet, but the code does compile, and Class2 can be dragged from the toolbox and does display the custom controls at design time on form1

    Any more thoughts?

    Imports System.windows.forms
    Public Class Class1(Of typUserControl1 As {UserControl, New}, typUserControl2 As {UserControl, New}, typUserControl3 As {UserControl, New}) '
     Inherits Panel
     Public Event SomeEvent(ByRef sender As Object, ByVal args As EventArgs)
    
    Protected Overrides Sub InitLayout()
      If Me.DesignMode = True Then
       Me.Controls.Clear()
       Dim tmpH As New UC1
       Me.Controls.Add(tmpH)
       tmpH.Visible = True
       tmpH.Top = 0
       tmpH.Left = 0
       Dim tmpR As New UC1
       Me.Controls.Add(tmpR)
       tmpR.Visible = True
       tmpR.Top = tmpH.Height + 1
       tmpR.Left = 0
       MyBase.InitLayout()
       MyBase.OnCreateControl()
      End If
      MyBase.InitLayout()
     End Sub
    
    End Class
    
    <System.ComponentModel.ToolboxItem(True)> _
    Public Class Class2
     Inherits Class1(Of UC1, UC1, UC1)
    End Class

      

     

    • Marked as answer by Karl Grear Tuesday, August 10, 2010 7:56 PM
    Tuesday, August 10, 2010 4:13 PM
  • check out this thread regarding the designer error when base class is abstract/generic

    http://social.msdn.microsoft.com/Forums/en-US/winformsdesigner/thread/afdfce40-8d7a-4300-bd8d-26e18c320a71

     

    best regards,
    Vladimir

    Tuesday, August 10, 2010 4:29 PM
  • OK,

    Class1 is derived from the System.Windows.Forms.Panel class
    Class2 is derived from Class1

    Because the Panel class is non generic I can double click on the Class1.vb file and our friendly neighborhood ‘To add components to your class’ designer pops up just fine.

    But because,  Class1 is generic when you double click the Class2.vb file you will receive the “Type.ContainsGenericParameters is true” error

    However if I create a third and otherwise useless class Class3 derived from Class2, and placed it in the top of the Class2.vb file, I can then double click the Class2.vb file and see the ‘To add components’ designer window which is actually displaying the designer for Class3 not Class2.

    Or

    I can just live with the designer window error as I will not be using it to design the class as it is a control based class not form based.

    If I create a regular class with no inheritance and double click the Class.vb file it opens straight to the code window.  Is it possible through an attribute or some other means to have Class2 open directly to code, and/or eliminate the designer thus solving the whole “Type.ContainsGenericParameters is true” error issue all together?

    • Marked as answer by Karl Grear Tuesday, August 10, 2010 7:55 PM
    Tuesday, August 10, 2010 6:57 PM
  • Or

    I can just live with the designer window error as I will not be using it to design the class as it is a control based class not form based.

    If I create a regular class with no inheritance and double click the Class.vb file it opens straight to the code window.  Is it possible through an attribute or some other means to have Class2 open directly to code, and/or eliminate the designer thus solving the whole “Type.ContainsGenericParameters is true” error issue all together?

    	[System.ComponentModel.DesignerCategory("")]
    	public partial class Form1 : Form
    	{
    		 // ...
    	}
    


    This will open code view directly when you click on the file .. you'll notice that the icon in the sln explorer gets changed too.


    best regards,
    Vladimir
    • Marked as answer by Karl Grear Tuesday, August 10, 2010 7:56 PM
    Tuesday, August 10, 2010 7:33 PM