Hi, hopefully this is an easy one:
I have mutiple namespaces contained within my main assembly for grouping similar classes.
For example, let's just say my assembly name is "MainAssembly", and in MainAssembly, I have the following namespaces:
MainAssembly.FirstLayer
MainAssembly.FirstLayer.a
MainAssembly.FirstLayer.SecondLayer
MainAssembly.FirstLayer.SecondLayer.a
MainAssembly.OutsideLayer
Ok, now in my Application that has a reference to this project. My
application has it's own namespace, so I need to include the assembly
namespace:
using MainAssembly;
However, when I add this namespace, I cannot see any of the nested
namespaces! The only way for my Application to see these, is by
including them:
using MainAssembly.FirstLayer
using MainAssembly.FirstLayer.a
using
MainAssembly.FirstLayer.SecondLayer
using MainAssembly.FirstLayer.SecondLayer.a
using
MainAssembly.OutsideLayer
There has to be something that I am doing wrong, but I wouldn't even
know the first thing to search for with this question, so I'm hoping
someone here can shed a little light on the subject:)

using nested namespaces in application
MagicM
using MainAssembly;
Why can't the Framework see that there are nested namespaces inside that assembly
Rob Wheeler
Also, if you wish to not use such lengthy text, you can do this...
using FirstLayer = MainAssembly.FirstLayer;
Then you can do this...
FirstLayer.SomeClass c = new FirstLayer.SomeClass();
Angel D
"A using directive does not give you access to any namespaces that are nested in the namespace you specify."
This is exactly what I'm trying to accomplish, but according to the quote above that I grabbed from link you gave me, this is not possible.
To see this in action for yourself:
For example; Open a new Windows Form Application, go into the FormLoad EventHandler. Make sure the "using System" directive is at the top and try typing "System.", and you can see the "Data" namespace is visible, so it is possible to type "System.Data". However the framework cannot see the "Data" namespace by itself (without typing "System."), even though the "using System" directive is included at the top of the application.
cliffz
Thank you all for all of the help:)
Alvin Kuiper
I understand what you mean. I did some test but I didn't do it properly. Sorry for that...
I had the WindowsApplication1 namespace and added a nested namespace WindowsApplication1.NestTest.
If the code is run inside WindowsApplication1 namespace it can reference the NestTest namespace without adding WindowsApplication1 in front.
If I use WindowsApplication1 namespace in another namespace like AnotherNamespace I can not reference objects in NestTest without adding WindowsApplication1 in front.
You probably have to have a using statement (with alias like Wendelldh suggest) or writing out the full namespace for the object.
JPATEL
I am not sure what you are trying to achieve but the using directive is used to define what namespaces that are used to resolve references to classes that are used.
http://msdn2.microsoft.com/en-us/library/sf0df423.aspx
If you have nested namespaces you will need to use using statement multiple times for each namespace you wish it should be able to resolve without qualifying the class name with its namespace.
If the .NET/project/COM is referenced in the project you can use all of its classes without using the using directive.
You can write
MainAssembly.FirstLayer.SomeClass c = new MainAssembly.FirstLayer.SomeClass();
If you use using you can reduce what you need to write
using MainAssembly;
FirstLayer.SomeClass c = new FirstLayer.SomeClass();
OutSideLayer.AnotherClass another = new OutSideLayer.AnotherClass();
If I add more using directives I can write it more compact
using MainAssembly;
using MainAssembly.FirstLayer;
using MainAssembly.OutSideLayer;
SomeClass c = new SomeClass();
AnotherClass another = new AnotherClass();
The using directive is not determining what classes you can use of referenced .NET components, project or COM classes, it helps in keeping the writing clear and readable. It also helps avoid collissions if you have to identical named classes but in different namespaces.
Fran431916
Hi,
As I have noticed, that is the default behavior of VS2005. You must refer to your namespace in your using declaration to be able to access it in your code. Remember that the code using system; would not enable you to access the Data namespace directly in your code althoug the data namespace is under the system namespace.
cheers,
Paul June A. Domag