Microsoft KB Archive/814605

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

Article ID: 814605

Article Last Modified on 11/14/2007

-

APPLIES TO


 * Microsoft Visual Basic 2005
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition

-



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 &quot;Applies to&quot; section.



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

Note In Visual Studio 2005, click Visual C# under Project Types. Under Templates, click Class Library. Name the project testScope, and then click OK.  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 } } </li> On the Build menu, click Build Solution to construct the testScope.dll class library.</li></ol>

Create a Test Visual Basic .NET or Visual Basic 2005 Application
<ol> On the File menu, point to Add Project, and then click New Project.</li> Under Project Types, click Visual Basic Projects.

Note In Visual Studio 2005, click Visual Basic under Project Types.</li> Under Templates, click Console Application.</li> Name the project testApp, and then click OK.</li> In Solution Explorer, right-click testApp, and then click Set as Startup Project.</li> In Solution Explorer, right-click References, and then click Add Reference.</li> On Add Reference, click Projects.</li> On Projects, click to select testScope, and then click OK.</li>  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 </li> On the Build menu, click Build Solution.

You may receive the error message in the &quot;Symptoms&quot; section of this article.</li>  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 } } </li> On the Debug menu, click Start.</li></ol>

Keywords: kbvs2005swept kbvs2005applies kbvs2002sp1sweep kbinterop kbimport kbformat kbexport kbdisplay kbdebug kbdevstudio kbdev kbdesigner kbcompiler kbbug KB814605

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.