xsharp.eu • The type or namespace name 'DbServer' could not be found
Page 1 of 1

The type or namespace name 'DbServer' could not be found

Posted: Wed Mar 10, 2021 10:45 pm
by ic2
Why is this?

Error: The type or namespace name 'DbServer' could not be found.
I have included VulcanVORddClasses.DLL where it is supposed to be found. Even if I change the code to:

VulcanVORddClasses.DBServer
it keeps giving the error.

When I set Enable implicit namespace lookup to true it works.

But I don't understand why an include is not enough?

Dick

The type or namespace name 'DbServer' could not be found

Posted: Wed Mar 10, 2021 10:57 pm
by robert
Dick,

In VO there were a limited number of classes. To distinguish between types in VO and to prevent name conflicts 3rd party vendors added prefixes to class names. AdoServer, bServer etc.
In .Net the number of classes is HUGE. And there are classes with similar names for different situations. For example there is a Control class for Windows Forms, for WPF and a Control class for VOGUI.
To distinguish between these classes with the same name and a different purpose they are grouped in namespaces.
Therefore the former Vulcan development team has also put the VO Classes in a namespace.
For Vulcan that namespace was Vulcan.VO. In X# we have simply used VO.

To make it easier to migrate code we have added a special attribute (metadata) to the Vulcan Assemblies and now also to the X# assemblies. This attribute tells the compiler in which namespaces the classes in the assembly are located.
If you enable the "Implicit Namespace Lookup" then the compiler will inspect these attributes and automatically add a "virtual" USING statement to each source file so the compiler "knows" in which namespaces to look for the types in the code.
The runtime also uses this mechanism if you create a class with CreateInstance().

Robert

The type or namespace name 'DbServer' could not be found

Posted: Thu Mar 11, 2021 11:49 am
by ic2
Hello Robert,

Thanks for the explanation.

I thought I had to use VulcanVORddClasses.DBServer without implicit namespace lookup. But with
Vulcan.VO.DbServer it works indeed.

I am doing this all the time because in .Net the designers didn't have enough fantasy to create unique class names so adding a class more than once results in Ambiguous Reference errors and the necessity to add the namespace, e.g. System.Drawing.Color because there is also a Color class in System.Windows.Media.Color. I've always wondered why no-one got the idea to create a System.Drawing.DrawingColor class and a System.Windows.Media.MediaColor class to prevent these errors completely....

Dick

The type or namespace name 'DbServer' could not be found

Posted: Thu Mar 11, 2021 2:02 pm
by Chris
Hi Dick,

That's exactly what they have done, they have produced unique names. The name "System.Drawing.Color" is one class name, it's not 3 things combined together. They could had named it "System_Drawing_Color" (or even SystemDrawingColor) instead, but apparently somebody thought it's a good idea to use dots instead of underscores in the class names, while the dot is already used for another million things in c#, and this is what's causing the confusion.

But you really need to treat System.Drawing.Point as THE class name, same with Vulcan.VO.DbServer etc. It's just that for saving typing long class names, compilers allow you to specify only the last part of the name and instead mention the first part (which by convention is called the "namespace" of the class, but that's just a convention, the namespace is nothing concrete) in USING statements.

The type or namespace name 'DbServer' could not be found

Posted: Thu Mar 11, 2021 3:34 pm
by ic2
Hello Chris,
The reason I find this an issue is that I often find a code snippet somewhere I could use without the namespace. So it says e.g.:

Something= Color.LightGray;
It compiles because I've included System.Drawing already or it does not and I have to find out which namespace I should use. Sometimes I choose the wrong one and only a while further (adding some more code) I find a line which does not work with System.Drawing and I have to start over again with (one of the) other namespaces.

Sometimes it is very clear of course but more than once I can not easily determine which namespace the sample is supposed to use. I really don't know if I am coloring a control if this control is supposed to be a Drawing or Media!

In that case it would be a lot easier if the class itself had a unique name. I normally have to type that namespace anyhow so a few more characters would not hurt.

It's an academic discussion of course, because it's already been named that way and ruined forever. But it's IMO one of the many samples of Microsoft delivering a poor result.

Dick