Article ID: 818411
Article Last Modified on 5/16/2007
APPLIES TO
- Microsoft Visual Basic .NET 2003 Standard Edition
- Microsoft Visual Basic .NET 2002 Standard Edition
SYMPTOMS
If your Windows Application project refers to both a Visual Basic .NET Class Library project and a Microsoft Visual C# .NET Class Library project, and you call a method in a Visual C# .NET class instance, you receive the following error message:
You only receive the error if you have all the following things:
- A Class Library project in Visual Basic .NET.
- A Class Library project in Visual C# .NET that refers to the Visual Basic .NET Class Library project.
- A method in Visual C# .NET that returns an instance of a Visual Basic .NET class.
RESOLUTION
To resolve this bug, refer to the assembly directly instead of adding references to the project. To do this, follow these steps:
- In Solution Explorer, expand References under WindowsApplication1.
- Right-click ClassLibrary1, and then click Remove.
- Right-click WindowsApplication1, and then click Add Reference.
- Click the .NET tab, and then click Browse.
- Locate ClassLibrary1.dll in the bin folder of ClassLibrary1.
- Click ClassLibrary1.dll, and then click Open.
STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.
MORE INFORMATION
Steps to Reproduce the Behavior
- In Microsoft Visual Studio .NET, start a new class library by using Visual Basic .NET.
By default, Class1.vb is created in ClassLibrary1. Add the following code to Class1.
Public Function display(ByVal i As Integer) As Integer Return i + 20 End Function
- On the File menu, point to Add Project, and then click New Project.
- In Add New Project, click to select Visual C# Projects under Project Types.
- Under Templates, click to select Class Library.
By default, ClassLibrary2 is created. - In Solution Explorer, right-click ClassLibrary2, and then click Add Reference.
- Click the Projects tab, and then click to select ClassLibrary1.
- Click Select.
- In Solution Explorer, right-click Class1.cs, click Rename, and then type Class2.cs.
- In Solution Explorer, right-click Class2.cs, and then click View Code.
Replace the existing code with the following code:
using System; //refer the Visual Basic Class Library using ClassLibrary1; namespace ClassLibrary2 { public class Class2 { //the method returns an object of type Class1 public Class1 GetItemObject() { return new Class1(); } } }
- On the Build menu, click Build Solution.
- On the File menu, point to Add Project, and then click New Project.
- Under Project Types, click to select Visual Basic Projects.
- Under Templates, click to select Windows Application.
By default, Form1 is created. - In Solution Explorer, right-click WindowsApplication1, and then click Add Reference.
- Click the Projects tab, and then click to select ClassLibrary1 and ClassLibrary2.
- Click Select.
Add the following code in the Load event of Form1:
'create an instance of the Visual Basic Class Dim vbobj As New ClassLibrary1.Class1() 'create an instance of Visual C# Class Dim csobj As New ClassLibrary2.Class2() 'call the GetItemObject method of Class2 vbobj = csobj.GetItemObject()
You may receive the error message mentioned in the "Symptoms" section of this article.
REFERENCES
For more information, visit the following MSDN Web site:
Adding and Removing References
http://msdn2.microsoft.com/en-us/library/wkze6zky(vs.71).aspx
Keywords: kbvs2005swept kbvs2005doesnotapply kbvs2002sp1sweep kbwindowsforms kbdll kbbug KB818411