Namespace and base class not recognized - Why? - vb.net

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).

Related

Xplat.Services.Maps.MapLocationFinder class

I installed the namespace XPlat.Services.Maps via NuGet. But now it seems to not contain the class MapLocationFinder.
When I type XPlat.Services.Maps.MapLocationFinder it results in an error that says there is no such member
However on this page its clearly using this class in this namespace.
https://xplat.gitbook.io/docs/xplat.services.maps/maplocationfinder
Is there something wrong?
XPlat.Services.Maps.MapLocationFinderResult for example works fine

Show Base Class throws error if base class is generic and in a class library

Say I have a class library project (Library) which contains a class of:
Public Class SomeClass(Of TTypeA, TTypeB)
Then, in another project UIProject in a different solution, I define a class that is derived from (inherits) SomeClass:
Imports Library
Public Class SomeDerivedClass
Inherits SomeClass(Of String, Boolean)
I have included Library.pdb and Library.xml alongside Library.dll (in the same folder) when I added the class libary reference to the UIProject.
Now, In UIProject I create a ClassDiagram (ClassDiagram1.cd), and add in the SomeClass class. So far so good.
The next step is to right-click on SomeClass in the diagram, and select "Show Base Class" from the dropdown. At this point, I am given the error:
Error HRESULT E_FAIL has been returned from a call to a COM
component.
If I do the same but for a non-generic version of SomeClass, then SomeClass is included in the class diagram, no problem.
No errors show up in ActivityLog.xml; nor in the Windows Event Viewer.
Is this a bug in Visual Studio (in which case I'll report it); or am I doing something wrong (and if so are there any other error logs or traces I can do to narrow down the issue further)?
The answer seems to be that COM does not work with generic types; and that it works in VS2017.

Base class '<baseclassname1>' specified for class '<partialclassname>' cannot be different

"Base class <baseclassname1> specified for class
'' cannot be different from the base class
'' of one of its other partial types"
The problem is that I only declared the class in one place, the actual class file, and only declared it once, non partially.
All my other classes that inherit from "DialogBase" work fine, but one file with the most code just stopped working.
What else could be the problem? Could it be declared partial somewhere else?
Class CostDialog inherits DialogBase(This works fine)
Class Blend inherits DialogBase(This errors)
Blend is only written as Public Class Blend in the Blend.vb file ONCE
This error makes no sense
You may have multiple code behind files with the same class name. I was converting a web site to a web application and found that there were two instances of Home. So Project/abc/home.aspx /aspx.vb and Project/def/home.aspx/ /aspx.vb will cause a conflict if both home.aspx.vb files have the same class name.
My fix was to leave all the file names untouched but modify the class name to abc_home and def_home in their respective code behind file and then change the Inherits property at the top of their .aspx pages.
Highly doubt this is still an issue for you, but maybe for someone else.

Class (Business Object) not appearing in Report Data toolbox for RDLC

I have created a local report in a class library (as embedded resource) and I want to use the existing business objects as the data source for the report. When I try to add the business object from the Report Data toolbox I cannot see the class that I want to choose. What I've noticed is that if the business object is a subclass of another class which exists in a another class library then it doesn't appear. Has anybody else seen this? So what I've tried is this:
Scenario 1:
Class Library 1
Reports folder > Report1.rdlc
BO folder > MyBO and MySuperClass
public class MyBO : MySuperClass
When I open up Report1.rdlc and try to create a New Object Data Source from the Report Data toolbox, MyBO class is visible and I can select it. If I change my solution to this:
Class Library 2
namespace ClassLibrary2 { public class MySuperClass { ... } }
Class Library 1
Reports folder > Report1.rdlc
BO folder > MyBO
public class MyBO : ClassLibrary2.MySuperClass
Now when I try to add the MyBO class it does not appear in the Report Data toolbox. Unfortunately I'm using a product and my Business objects have to be subclasses of the super class that is in the other class library.
Does anyone know how to fix this issue or is this a bug? Oh, I'm using .Net 4 and VS2010. Thanks.
Kind regards
Sidharth
I found the same issue today and tracked it to the fact that when the project is compiled as 64-bit in Debug mode that the Data Source Wizard does not find anything. If you switch to x86, they magically appear. I guess the Wizard is 32-bit.
My current work around is to set Debug mode to x86 and Release to x64. In this way, I can edit datasources as need be. The final Release doesn't have any problem running.
However, I did not see it dependent on being a sub-class. Maybe your other libraries have Debug set to x86 and hence the wizard works.

Why Can't I Inherit IO.Directory?

Why can't I create a class in VB.NET that inherits System.IO.Directory? According to Lutz Roeder, it is not declared as NotInheritable!
I want to create a utility class that adds functionality to the Directory class. For instance, I want to add a Directory.Move function.
Please advise and I will send you a six pack. OK nevermind I'm not sending you anything but if you come to the bar tonight I will hook you up and then beat you in pool.
From the Meta Data of .NET
namespace System.IO
{
// Summary:
// Exposes static methods for creating, moving, and enumerating through directories
// and subdirectories. This class cannot be inherited.
[ComVisible(true)]
public static class Directory
You cannot inherit from a Static Class.
Are you using C# 3.0 VB.NET 2008 -- then you could add an Extension Method
If you use the DirectoryInfo class, you will have access to a MoveTo function.
EDIT: I'll correct myself... The static Directory class already has a Move method.
I'd guess that Reflector isn't picking up the sealed attribute correctly for VB (or perhaps just not displaying it properly). If you look at the IL, it is sealed:
class public abstract auto ansi sealed beforefieldinit Directory