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 s开发者_运维知识库tuff.
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.
class2
, and re-add it and paste back its contents, it still won't work.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.
精彩评论