1

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.

Toerndev
  • 715
  • 1
  • 6
  • 21
  • 1
    Can you share with us the class declarations and also the way you are using the classes from the code? – Davide Piras Jun 17 '11 at 05:58
  • @Davide The contents of the classes are fine, because everything works if I copy class2 to another class. There seems to be something wrong with the name of class2, will update my question. – Toerndev Jun 17 '11 at 06:54
  • Do you have something else in your code, either written by you or in a different namespace called 'class2' ? If now you've renamed it and type `class2.` Into vb do you get any intellisense? – CResults Jun 17 '11 at 07:02
  • @CResults Bingo, I found that the following had magically been added to the class: "Private Function FloatingNumbersWhileAdd() As Object Throw New NotImplementedException End Function". That solved it. What a waste of time, I'm not used to such things appearing automatically. Thanks! – Toerndev Jun 17 '11 at 07:07

1 Answers1

1

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.

CResults
  • 5,100
  • 1
  • 22
  • 28
  • Yes, thank you! Do you know under what circumstances that code block would appear? Because I certainly did not put it there. – Toerndev Jun 18 '11 at 00:32
  • It sounds like code that would be added by VS to sy "don't forget to implement this function" - for example when you override a baee class which has functions tagged with `MustOverride`. In the partiular instance i'm not 100% sure though! – CResults Jun 18 '11 at 07:37