VB.NET automatically prefixes the root namespace set in the project properties to the namespace of each class. This is different from C#, where the full namespace must be declared each time.
Is it possible to override this behaviour, creating a namespace outside of the root namespace?
If I understand you correctly you just need to set a blank namespace in the project properties dialog and then set namespaces within each source file using Begin/End Namespace commands.
From VS2012 onwards it's possible to get around this, see stackoverflow.com/a/17360357/233095
Defining the default for the project as blank and then taking total control in each class allows you to do what c# does. However certain project types (Library I believe) do not allow you to change the default namespace to blank.
Use of the Global keyword does not allow you to jump out of the root namespace either:
http://msdn.microsoft.com/en-us/library/16czfx55.aspx
They now implemented it:
Namespace Global.MyNamespace
End Namespace
You can change the namespace of the entire project by going to properties on the project.
else you will have to have a empty root namespace and set the name space in each file with the
Namespace test
class.....
End Namespace
Related
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).
"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.
I have added the below tag to my xaml but it didn't get recognized.I have the namespace xmlns:bing="using:Bing.Maps" added in the list of namespaces.
I have also installed bing sdk for wondows store from
http://visualstudiogallery.msdn.microsoft.com/bb764f67-6b2c-4e14-b2d3-17477ae1eaca
That control has been deprecated. If you can use the new map control in the Microsoft.Phone.Maps.Controls namespace. How-To
I have a dll where i would like to access the global variables of the Project.
How can this be done in VB6?
You can not access anything in a different project unless you explicitly pass it between the projects via COM.
While it is syntactically correct to use a global variable it is a very poor idea. Add either a module or a class file and encapsulate your variable inside a property. If you want to access your properties from within your project a bas file is fine. If you are describing making an ActiveX dll and accessing properties with another, separate project you should make a class module. You will need to set the class Instancing property to something other than private.
'myproject.bas code
Option Explicit
private mblnIsDirty as boolean
Public Property Let IsDirty(ByVal vIsDirty)
mblnIsDirty = vIsDirty
End Property
Public Property Get IsDirt() As Boolean
IsDirty = mblnIsDirty
End Property
I am trying to get this: System.Deployment.Application.ApplicationDeployment.CurrentDeployment.IsFirstRun
But the application namespace is not there. I just see System.Deployment.Internal. The object browser, however, shows me all the properties and methods of that namespace, but my app can't see it.
What am I missing?
Did you add a reference to System.Deployment?