I have a class that inherits from a base class (this contains a lot of common db related stuff amongst other things and is marked as MustInherit). I want to write a shared method in which I call a base class method, however the compiler gives me the message ‘MyBase is only valid within an instance method’. This shared method is a logging method and will be used a lot within the app, I’m trying to avoid having to instantiate an object each time I want to call it.
Is it possible to access the base class methods from a shared method?
No, as the compiler states you cannot call an instance method from a shared method.
Since an instance of a class is separate from any other instance each call to a method on that instance can potentially create different results and side-effects as an instance method has access to the instance’s state. A shared method does not have access to the state of any instance since the shared method is shared between all instance of the type.
Since this is the case it is impossible to call an instance method from a shared method because a shared method is “instance-less”.