BUG: "Type <Class Name> is not defined" error message when you try to inherit a protected nested class in Visual Basic .NET (820656)



The information in this article applies to:

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

SYMPTOMS

When you try to inherit a protected nested class in Visual Basic .NET, you receive the following compilation error message:
Type Protected Class Name is not defined

WORKAROUND

To work around this problem, change the protected nested class to a public nested class. When you inherit the nested class, qualify the nested class with a parent class. The following code demonstrates the workaround for the example that is listed in the "More Information" section of this article:
Option Explicit On 
Option Strict On

Public Class OuterBase
    Public Sub New()
        'Constructor
    End Sub
    'Modify this class as public.
    Public Class InnerBase
        Private a As Integer

        Public Sub New()
            'Constructor
        End Sub
    End Class
End Class


Public Class OuterDerived
    Inherits OuterBase

    Dim ia As OuterBase.InnerBase
    'Qualify the Nested class with its Parent.
    Protected Class InnerDerived
        Inherits OuterBase.InnerBase

        Public Sub New()
            'Constructor
        End Sub
    End Class

    Public Sub New()
        'Constructor
    End Sub
End Class

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

  1. Start Microsoft Visual Studio .NET.
  2. On the File menu, point to New, and then click Project.
  3. Click Visual Basic Projects under Project Types, click Class Library under Templates, and then click OK. By default, Class1 is created.
  4. Paste the following code in class1:
    Option Explicit On 
    Option Strict On
    
    Public Class OuterBase
        Public Sub New()
            'Constructor
        End Sub
        'Define a protected class.
        Protected Class InnerBase
            Private a As Integer
    
            Public Sub New()
                'Constructor
            End Sub
        End Class
    End Class
    
    
    Public Class OuterDerived
        Inherits OuterBase
    
        Dim ia As OuterBase.InnerBase
        'Inherit protected nested class.
        Protected Class InnerDerived
            Inherits InnerBase
    
            Public Sub New()
                'Constructor
            End Sub
        End Class
    
        Public Sub New()
            'Constructor
        End Sub
    End Class
    
  5. On the Build menu, click Build Solution. You receive the compilation error message that is listed in the "Symptoms" section of this article.

REFERENCES

For more information about implementing nested classes, visit the following Microsoft Developer Network (MSDN) Web site:

Modification Type:MinorLast Reviewed:2/3/2006
Keywords:kbvs2005doesnotapply kbvs2005swept kbvs2002sp1sweep kbProgramming kbcode kbInheritance kberrmsg kbbug KB820656 kbAudDeveloper