'<nomemetodo>' non è accessibile in questo contesto perché il tipo restituito non è accessibile

Aggiornamento: novembre 2007

'<methodname>' is not accessible in this context because the return type is not accessible

È stata chiamata una funzione con un tipo restituito a cui non è possibile accedere dall'istruzione di chiamata. Nel codice seguente, ad esempio, la chiamata da Main a PublicMethod non riesce perché il tipo restituito, PrivateType, viene dichiarato con il modificatore di accesso Private nella classe TestClass. Pertanto, il contesto all'interno del quale è possibile accedere a PrivateType è limitato a TestClass.

Class TestClass

    Dim pT As New PrivateType

    Private Class PrivateType
    End Class

    '' A corresponding error is returned in this line: 'PublicMethod 
    '' cannot expose 'PrivateType' in namespace 'ConsoleApplication1' 
    '' through class 'TestClass'.
    'Public Function PublicMethod() As PrivateType
    '    Return Nothing
    'End Function

End Class

Module Module1

    Sub Main()

        Dim tc As TestClass
        '' This error occurs here, because the data type returned by 
        '' PublicMethod()is declared Private in class TestClass and 
        '' cannot be accessed from here.
        'Console.WriteLine(tc.PublicMethod())

    End Sub

End Module

ID errore: BC36665 e BC36666

Per correggere l'errore

  • Se la definizione del tipo è accessibile, impostare il modificatore di accesso da Private su Public.

  • Se si dispone dell'accesso, modificare il tipo restituito della funzione.

  • Scrivere un metodo o un metodo di estensione che restituisca un tipo accessibile.

Vedere anche

Concetti

Livelli di accesso in Visual Basic