VB.NET 看不到某些类

发布于 2024-11-16 06:28:47 字数 1030 浏览 2 评论 0原文

我的一门课程似乎对我的项目的其余部分来说是不可见的。我想知道我是否必须先初始化它才能使用它的公共内容。

Class1 的函数和方法立即出现在 IntelliSense 中,但 Class2 被视为一般(未知)对象。

我在 Class1Class2 中有一些 Public Shared 函数。我可以正常调用函数

Class1.myPublicSharedFunction()

。然而,当我使用 Class2 中的任何函数尝试此操作时,我收到错误:

Error   1   Option Strict On disallows late binding.

即使它们的类型当然已声明。如果我将工作函数从 Class1 复制并粘贴到 Class2 并尝试调用它,它就会开始给出相同的错误。我在 Class2 中声明的任何测试函数都无法识别其类型,因此被指控尝试进行后期绑定。

这两个类都是公共的,并且所有提到的函数都是公共共享。我不明白是什么让课程的运作方式有所不同。就好像我需要在 VB 知道其函数类型之前加载或编译 Class2,但这些事情在 VB 中应该是自动的。

这可能是什么原因造成的?

当我开始输入 Class2. 时,IntelliSense 列表是一个函数,而 Class1 被识别为一个类。

编辑: 如果我将 Class2 的确切内容复制到新类中,只需将行 Public Class ... 更改为新名称,一切都会正常工作。我认为可能是名称太长,所以我将类复制到 AnotherClassWithAReallyLongName,但这个也有效。
但是,如果我删除 class2,然后重新添加它并粘贴回其内容,它仍然无法工作。

One of my classes seems to be invisible to the rest of my project. I wonder if I somehow have to initialize it before I can use its public stuff.

The functions and methods of Class1 immediately appear in IntelliSense, but Class2 is treated like a general (unknown) object.

I have some Public Shared functions in Class1 and Class2. I can call functions using

Class1.myPublicSharedFunction()

normally. However when I try this with any function from Class2, I get the error:

Error   1   Option Strict On disallows late binding.

even though their types are of course declared. If I copy and paste a working function from Class1 to Class2 and try to call it, it starts giving the same error. Any test function I declare in Class2 doesn't get its type recognized and is thus accused of trying to do late binding.

Both classes are public, and all the functions mentioned are Public Shared. I don't understand what makes the classes work differently. It's as if I needed to load or compile Class2 before VB knows its function types, but these things are supposedly automatic in VB.

What could be the cause of this?

When I begin typing Class2., IntelliSense lists is as a function, while Class1 is recognized as a class.

EDIT:
If I copy the exact contents of Class2 into new class, only changing the line Public Class ... to the new name, everything works as normal. I thought it might be that the name was too long, so I copied the class to AnotherClassWithAReallyLongName, but this one worked too.
However, if I delete class2, and re-add it and paste back its contents, it still won't work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

混吃等死 2024-11-23 06:28:47

根据评论,您的代码中还有一些名为“Class2”的内容隐藏了您的新类定义。删除它/重命名它,你的类就可以工作了。

As per comment you have something else in your code named `Class2’ that is hiding your new class definition. Remove it/rename it and your class will work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文