通过


“<methodname>”是不可访问的返回类型,因此它在此上下文中不可访问。

你调用了具有不能从调用方语句访问的返回类型的函数。 例如,在下面的代码中,从 Main 调用 PublicMethod 失败,因为返回类型 PrivateType是用类 Private 中的 TestClass访问修饰符声明的。 因此,可在其中访问 PrivateType 的上下文仅限于 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: BC36665 和 BC36666

更正此错误

  • 如果可访问类型定义,请将访问修饰符从 Private 更改为 Public

  • 如果你有权访问函数的返回类型,请更改它。

  • 编写返回可访问类型的方法或扩展方法。

另请参阅