A Visual Studio Bug
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:
- Create a new solution.
- Add a ClassLibrary project called ClassLibrary1.
- Add a ClassLibrary project called ClassLibrary2
- Add a WIndows Control project called WindowsControlLibrary1.
- In ClassLibrary2, add an interface called IParameter.
- In ClassLibrary1, add an interface called ITest.
- Add a single method to ITest: "Sub TestRoutine(obj as IParameter)"
- In the WindowsControlLibrary1 project, add a usercontrol called UserControl1.
- 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.
- In UserControl1, implement ITest. You don't need any code in the method; just include the stub.
- Now, recompile, and try to "add an inherited control" again.
- See the error:
- ---------------------------
Assembly Load Error
---------------------------
Unable to load assembly '<path>\WindowsControlLibrary1.dll'. Ensure that the file is a valid .Net Framework assembly.
---------------------------
OK
---------------------------
- Now, if you move ITest to the Control Library or to ClassLibrary2, it will succeed again :-)
- Interestingly enough, if you change ITest.TestRoutine(obj as IParameter) to ITest.TestRoutine(), the inheritance picker will work again.
- 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>