So I am working on a project someone gave me.
In the project, there is a main Namespace
, lets call it "Program
".
In that namespace are several different classes.
Now I had to derive from a class in Namespace Devices
.
There was already another class derived from the object Device
.
So I went ahead, created my class, included it in the Devices
namespace, derived it from Device
and did my job.
But not shortly afterwards, I couldnt use any of the base variables, methods and so on. The whole intellisense doesnt work on that class. And even worse is, that it doesnt seem to be included into the assembly.
How can I get my class being recognized by Intellisense, the assembly and so on? I made a test class which only was like this:
Namespace Devices
Class Testcle
' ... Nothing
End Class
End Namespace
And it worked perfectly fine. It was included in the assembly, Intellisense worked, etc.
The folder structure looked a bit like this:
[Project]
↳ [-] Devices (Folder and Namespace)
[-] AlreadyExistingClassDerivedFromDevice (Folder)
↳ AlreadyExistingClassDerivedFromDevice.vb
[-] MyClassDerivedFromDevice (Folder)
↳ MyClassDerivedFromDevice.vb
↳ [+] Other (Folder)
↳ Testcle.vb
↳ Device.vb
Is there anything Im missing? Like is there a hidden setting I have to activate?
Edit: The declarations look a bit like this (but in different files):
Device.vb
Namespace Devices
Public MustInherit Class Device
' ...
End Class
End Namespace
This works:
AlreadyExistingClassDerivedFromDevice.vb
Namespace Devices
Public NotInheritable Class AlreadyExistingClassDerivedFromDevice
Inherits Device
' ...
End Class
End Namespace
This doesnt work:
MyClassDerivedFromDevice.vb
Namespace Devices
Public NotInheritable Class MyClassDerivedFromDevice
Inherits Device
' ...
End Class
End Namespace
There is literally no difference with the inheriting classes. Only the inner workings. But those shouldnt have an effect on the accessability of the ctor or Intellisense or something, right?
I write this as an answer because it solved my problem. However, I dont know what cause it had and dont know the exact steps to actually solve the problem in a 'proper' way.
What I did is the following:
I renamed the file MyClassDerivedFromDevice.vb
to MyClassDerivedFromDevice_Old.vb
, created a new class named MyClassDerivedFromDevice.vb
and just after adding the namespace and making sure Intellisense and everything works properly, I just copied the code from MyClassDerivedFromDevice_Old.vb
(after the line Namespace Devices
up to End Namespace
into MyClassDerivedFromDevice.vb
.
That solved the problem.
Short version:
1) Rename NotWorkingClass.vb
to NotWorkingClass_Old.vb
2) Add new class with name NotWorkingClass.vb
.
3) Add Namespaces to NotWorkingClass.vb
.
4) Check whether everything works accordingly (Intellisense, etc.) and it is recognized by Visual Studio.
5) Copy all code starting after Namespace X
to right before End Namespace
from NotWorkingClass_Old.vb
to NotWorkingClass.vb
(which should now work).