访问本地 class

Access a local class

我无法从其他 classes 和模块访问 class(实际上是几个 classes),所有这些都在同一个 vb.net(Asp.net) 项目。

这是我无法导入或访问的 classes 之一的示例: (此文件在 \App_Code 文件夹中 clsPitch.vb)

Imports Microsoft.VisualBasic
Public Class clsPitch
    Public MyStuff As String
End Class

在同一项目的另一个 class 中:

Dim ThisClass As clsPitch

这给出了以下错误: "Type 'clsPitch' is not defined."

Imports MyProject.clsPitch

这给出了以下错误: "Namespace or type specified in the imports 'MyProject.clsPitch' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases."

当我键入 "Imports.MyProject." none 时,其中 class 会出现在智能感知中。

我没有指定任何命名空间(我的理解是整个项目的一切都应该在一个命名空间中)。

奇怪的是我还有一个基本定义相同的class,而且工作正常(我可以访问它并导入它)。

右键单击 App_Code 文件夹中的 .vb 文件并查看其属性。确保 Build Action 设置为 Compile