October 2005 - Posts

I found a weird bug related to attempting to add an inherited control to a VS .NET project. Here are the steps to reproduce:


Here's how to recreate it in Visual Studion .NET 2003 using VB .NET:

  1. Create a new solution.
  2. Add a ClassLibrary project called ClassLibrary1.
  3. Add a ClassLibrary project called ClassLibrary2
  4. Add a WIndows Control project called WindowsControlLibrary1.
  5. In ClassLibrary2, add an interface called IParameter.
  6. In ClassLibrary1, add an interface called ITest.
  7. Add a single method to ITest: "Sub TestRoutine(obj as IParameter)"
  8. In the WindowsControlLibrary1 project, add a usercontrol called UserControl1.
  9. Go ahead and compile the program, and prove that you can "add an inherited control" and that the inheritance picker successfully findes UserControl1 and adds it to the dialog.
  10. In UserControl1, implement ITest. You don't need any code in the method; just include the stub.
  11. Now, recompile, and try to "add an inherited control" again.
  12. See the error:
  13. ---------------------------
    Assembly Load Error
    ---------------------------
    Unable to load assembly '<path>\WindowsControlLibrary1.dll'.  Ensure that the file is a valid .Net Framework assembly.
    ---------------------------
    OK  
    ---------------------------
  14. Now, if you move ITest to the Control Library or to ClassLibrary2, it will succeed again :-)
  15. Interestingly enough, if you change ITest.TestRoutine(obj as IParameter) to ITest.TestRoutine(), the inheritance picker will work again. 
  16. Also, if ITest.TestRoutine() is a function that returns type IParameter, the same problem will occur.

<Code>

ClassLibrary1

Public Interface ITest

Function Test() As ClassLibrary2.IParameter

'Sub TestRoutine(ByVal obj As ClassLibrary2.IParameter) ' Fails

'Sub TestRoutine() ' Passes

End Interface

ClassLibrary2

Public Interface IParameter

End Interface

WindowsControlLibrary1

Public Class UserControl1

Inherits UserControl

Implements ITest

'WINDOWS FORMS DESIGNER GENERATED CODE

'Public Sub TestRoutine(ByVal obj As ClassLibrary2.IParameter) Implements ITest.TestRoutine

' ' fails

'End Sub

Public Function Test() As IParameter Implements ITest.Test

' fails

End Function

'Public Sub TestRoutine() Implements ClassLibrary1.ITest.TestRoutine

' ' Passes

'End Sub

End Class

</Code>

Posted by taganov | 4 comment(s)
Filed under:
More Posts