Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to find the root namespace programmatically

30 views
Skip to first unread message

Saumendra

unread,
May 9, 2003, 9:52:30 PM5/9/03
to
Hi.
When creating a project in visual studio.net, the ide creates a root
namespace for the project. Well we can change that root namespace to any
name that we want.
My question is, are there any methods available that will provide me the
name of my root namespace. Right now I am searching the class references
under the System.Reflection namespace, and I can't find any method to
display the root namespace of the project.
Thanx.

Saumendra

Tom Spink

unread,
May 11, 2003, 8:14:52 AM5/11/03
to
Hi, try this:

Dim strNameSpace As String =
Reflection.Assembly.GetExecutingAssembly.GetName.Name.ToString

--
Happy to help,
-- Tom Spink
(thomas...@ntlworld.com)


"Saumendra" <s...@no-spam.com> wrote in message
news:Oez2NbpF...@TK2MSFTNGP10.phx.gbl...

Saumendra

unread,
May 11, 2003, 8:55:36 AM5/11/03
to
Dim strNameSpace As String =
Reflection.Assembly.GetExecutingAssembly.GetName.Name.ToString provides me
the name of my assembly. It does not provide me the name of my root
namespace. The root namespace can be the same as the assembly name or it can
be different.
If u go to solution explorer, and right click on a project, and view its
properties, u will see that the "root namespace" is mentioned under "Common
Properties-> General-> Application->Root Namespace". This is the string that
I want to retrieve via code. Any hints ?

Saumendra

Hi Tom,
The code that u pr

"Tom Spink" <thomas...@ntlworld.com> wrote in message
news:OVsR8a7F...@tk2msftngp13.phx.gbl...

Armin Zingler

unread,
May 11, 2003, 11:39:33 AM5/11/03
to
"Saumendra" <s...@no-spam.com> schrieb

Why not get *any* type in the assembly and take the first part of the string
(up to "."c)?


--
Armin

Saumendra

unread,
May 11, 2003, 2:20:59 PM5/11/03
to
Hello Armin,
Can u kindly provide a sample code, cause I am not clear on what u are
saying.
Thanx.

Saumendra


> Why not get *any* type in the assembly and take the first part of the
string
> (up to "."c)?
>

> Armin


Armin Zingler

unread,
May 11, 2003, 5:54:01 PM5/11/03
to
"Saumendra" <s...@no-spam.com> schrieb

> > Why not get *any* type in the assembly and take the first part
> > of the
> string
> > (up to "."c)?
>
> Can u kindly provide a sample code, cause I am not clear on what
> u are saying.

Imports System.Reflection

'...
Dim Assy As [Assembly]
Dim Types As Type()
Dim Pos As Integer
Dim TypeName As String

Assy = [Assembly].GetExecutingAssembly
Types = Assy.GetTypes()
TypeName = Types(0).FullName
Pos = TypeName.IndexOf("."c)
MsgBox("Root namespace: " & TypeName.Substring(0, Pos))

--
Armin

Saumendra

unread,
May 12, 2003, 9:49:22 AM5/12/03
to
Armin,
U know what.. Actually u are very close to what I am looking for, but then
there is a bug in the code, which is, suppose there is a value for the Root
Namespace set in my project properties, then your solution will work, but
then , if the Project's Root Namespace is set to blank, then your solution
will not work.
What I am looking for the is the Root Namespace that Visual Studio creates.

There is a property called "DefaultNamespace" under the "Visual Basic and
Visual C# ProjectItem Object" mentioned in the docs, and I have struggled
one whole day behind it and I just can't figure out how to use it. There is
a namespace called "VSLangProj" and I guess I have to make use of it. This
is done by adding a reference "VSLangProj" to the project and then
importing VSLangProj.

Any other suggestions ??

becuase it will then show the root namespace of the class that is
"Armin Zingler" <az.n...@freenet.de> wrote in message
news:%23JvKlJB...@TK2MSFTNGP10.phx.gbl...

Armin Zingler

unread,
May 12, 2003, 10:08:51 AM5/12/03
to
"Saumendra" <s...@no-spam.com> schrieb

> Armin,
> U know what.. Actually u are very close to what I am looking
> for, but then there is a bug in the code, which is, suppose
> there is a value for the Root Namespace set in my project
> properties, then your solution will work, but then , if the
> Project's Root Namespace is set to blank, then your solution
> will not work. What I am looking for the is the Root Namespace
> that Visual Studio creates.
>
> There is a property called "DefaultNamespace" under the "Visual
> Basic and Visual C# ProjectItem Object" mentioned in the docs,
> and I have struggled one whole day behind it and I just can't
> figure out how to use it. There is a namespace called
> "VSLangProj" and I guess I have to make use of it. This is done
> by adding a reference "VSLangProj" to the project and then
> importing VSLangProj.
>
> Any other suggestions ??

At runtime, there is no "root namespace" information. It's just there for
the compiler in which namespace to put the classes. BTW, I've never had a
project without a root namespace so far.


--
Armin

Abel Valadez [MSFT]

unread,
May 13, 2003, 5:16:40 PM5/13/03
to
The "root namespace" is only useful at design time. If you are interested
in getting the "root namespace" during design time, you should try the
language properties automation as stated earlier in the thread. However,
once the project is compiled, it is treated as any other namespace so there
isn't any way to get it.

Hope this helps.

Abel, VB Team
This posting is provided "AS IS" with no warranties, and confers no rights.

0 new messages