Delen via


Type '<typename>' cannot inherit from a type nested within it

A class or interface definition includes an Inherits Statement that specifies a type nested within it.

Inheritance must be linear, not circular. A type cannot inherit from a type that inherits from it.

A related restriction is that a type cannot inherit from a type that is not yet defined. Inheritance involves the ability to reuse members of the base class, which in turn requires that these members be defined. Therefore, Visual Basic cannot compile code such as the following example.

Public Class outerClass
    ' The following statement is INVALID because innerClass is not defined.
    Inherits innerClass
    Public Class innerClass
        Public Sub doSomething()
        End Sub
    End Class
End Class

Error ID: BC30908

To correct this error

  • If the inheriting type (the outer type in the nesting) must inherit from the inner type, move the inner type out of the outer type.

  • If the inner type must be nested within the outer type, the outer type cannot inherit from it. Remove the Inherits Statement.

See Also

Other Resources

Inheritance in Visual Basic