BUG: You cannot resolve private and public nested types in Visual Basic .NET or in Visual Studio 2005 (814605)



The information in this article applies to:

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

SYMPTOMS

In a namespace, you may create classes with the same name but different cases. To do this, use case-sensitive languages, such as Microsoft Visual C# .NET. You can also access these classes in case-sensitive languages. In languages that are not case-sensitive, such as Microsoft Visual Basic .NET or Microsoft Visual Basic 2005, you may receive the following compilation error when you try to access these classes:
'NameSpace.ClassName' is not accessible in this context because it is 'Private'.

CAUSE

This problem occurs because Visual Basic .NET or Visual Basic 2005 is not a case sensitive language. If you access objects in an assembly, the Visual Basic .NET or Visual Basic 2005 parser returns the first occurrence of the class in the assembly. If the first occurrence of the object is not public in scope, the compiler creates an error.

WORKAROUND

To work around this problem, declare the classes that have public access modifiers first, and then declare the classes that have non-public scopes.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.

MORE INFORMATION

Steps to Reproduce the Behavior


Create a Visual C# .NET Library

  1. Open Microsoft Visual Studio .NET or Microsoft Visual Studio 2005.
  2. On the File menu, point to New, and then click Project.
  3. Under Project Types, click Visual C# Projects.

    Note In Visual Studio 2005, click Visual C# under Project Types.
  4. Under Templates, click Class Library.
  5. Name the project testScope, and then click OK.
  6. Replace the existing code in Class1.cs with the following code:
    using System;
    
    namespace Testscope
    {
       class MYTESTCLASS
       {	// Internal class in CAPITAL case
       }
     
       public class mytestclass
       {	// Public Class in small case
       }
    }
  7. On the Build menu, click Build Solution to construct the testScope.dll class library.


Create a Test Visual Basic .NET or Visual Basic 2005 Application

  1. On the File menu, point to Add Project, and then click New Project.
  2. Under Project Types, click Visual Basic Projects.

    Note In Visual Studio 2005, click Visual Basic under Project Types.
  3. Under Templates, click Console Application.
  4. Name the project testApp, and then click OK.
  5. In Solution Explorer, right-click testApp, and then click Set as Startup Project.
  6. In Solution Explorer, right-click References, and then click Add Reference.
  7. On Add Reference, click Projects.
  8. On Projects, click to select testScope, and then click OK.
  9. Replace the existing code in Module1.vb with the following code:
    Imports Testscope
    Module Module1
        Sub Main()
            ' Create an Object of Public mytestclass class
            Dim obj As New mytestclass()
        End Sub
    End Module
  10. On the Build menu, click Build Solution.

    You may receive the error message in the "Symptoms" section of this article.
  11. Replace the code in Class1.cs with the following code:
    using System;
    
    namespace Testscope
    {
       public class mytestclass
       {	// Public Class in small case
       }   
       
       class MYTESTCLASS
       { // Internal class in CAPITAL case
       }
    }
    
  12. On the Debug menu, click Start.

Modification Type:MinorLast Reviewed:10/3/2006
Keywords:kbvs2005swept kbvs2005applies kbvs2002sp1sweep kbinterop kbImport kbformat kbExport kbdisplay kbDebug kbDevStudio kbDev kbDesigner kbCompiler kbbug KB814605 kbAudDeveloper