BUG: You receive a "Reference required to assembly" error message when you run a Visual Basic .NET application (818411)



The information in this article applies to:

  • Microsoft Visual Basic .NET (2003)
  • Microsoft Visual Basic .NET (2002)

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:
Reference required to assembly 'ClassLibrary1' containing the type 'ClassLibrary1.Class1'. Add one to your project.
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:
  1. In Solution Explorer, expand References under WindowsApplication1.
  2. Right-click ClassLibrary1, and then click Remove.
  3. Right-click WindowsApplication1, and then click Add Reference.
  4. Click the .NET tab, and then click Browse.
  5. Locate ClassLibrary1.dll in the bin folder of ClassLibrary1.
  6. 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


  1. In Microsoft Visual Studio .NET, start a new class library by using Visual Basic .NET.

    By default, Class1.vb is created in ClassLibrary1.
  2. Add the following code to Class1.
    Public Function display(ByVal i As Integer) As Integer
        Return i + 20
    End Function
  3. On the File menu, point to Add Project, and then click New Project.
  4. In Add New Project, click to select Visual C# Projects under Project Types.
  5. Under Templates, click to select Class Library.

    By default, ClassLibrary2 is created.
  6. In Solution Explorer, right-click ClassLibrary2, and then click Add Reference.
  7. Click the Projects tab, and then click to select ClassLibrary1.
  8. Click Select.
  9. In Solution Explorer, right-click Class1.cs, click Rename, and then type Class2.cs.
  10. In Solution Explorer, right-click Class2.cs, and then click View Code.
  11. 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();
                    }
               }
    }
    
  12. On the Build menu, click Build Solution.
  13. On the File menu, point to Add Project, and then click New Project.
  14. Under Project Types, click to select Visual Basic Projects.
  15. Under Templates, click to select Windows Application.

    By default, Form1 is created.
  16. In Solution Explorer, right-click WindowsApplication1, and then click Add Reference.
  17. Click the Projects tab, and then click to select ClassLibrary1 and ClassLibrary2.
  18. Click Select.
  19. 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:

Modification Type:MinorLast Reviewed:2/3/2006
Keywords:kbvs2005swept kbvs2005doesnotapply kbvs2002sp1sweep kbWindowsForms kbDLL kbbug KB818411 kbAudDeveloper