views:

328

answers:

4

Ok, I guess do namespaces have to be the same as the nested folders that their in? I keep getting errors saying that the namespace should be xxx.yyy.zzz.

Example:

Folder1
    Folder2
        MyControl.cs

I have a namespace in it defined as:

namespace CustomControls
{

...

}

so the compiler is complaning that it must be namespace Folder1.Folder2

so is there a direct relation to file structure and namespaces? Are you forced to have a tight relation to these?

+2  A: 

I don't know whether ASP.NET has some special rules (due to automatic compilation) but certainly in C# itself there are no rules saying you have to organise your folders to match your namespaces. It's a good idea from a maintainability point of view though.

Are you sure it's the compiler and not just another bit of ASP.NET (or even ReSharper?) complaining?

Jon Skeet
+1  A: 

No. You can have any namespace tree you want regardless of your folder structure. Visual Studio makes it easy on you to automatically create namespaces based on folder structure so you don't have to maintain namespace trees yourself. But does not force it in any ways shape or form.

The error you're getting doesn't have anything to do with your compiler.

You also don't have any tag saying what Dev IDE you're using.

Robert Koritnik
+5  A: 

This is a warning Resharper usually reports. To exclude a folder from Resharper's folder tree - namespace comparison, go to the folder properties list in VS and set Namespace Provider to false.

kek444
What menus is this in? I'm using VS 2008. And yes I'm using ReSharper so that must be it
CoffeeAddict
F4 opens the properties window if you don't have it open, then simply click on the folder in solution explorer and its properties will show up in the properties view.
kek444
A: 

That has to be an error coming from ReSharper and not from Visual Studio's compiler. Right now I am actually having the opposite problem: I am trying to get VS2008 to automatically name my namespaces based on my nested folder structure like Folder1.Folder2.MyProjectName but it insists on naming it "flat" MyProjectName! So as Jon said, C# in itself is agnostic to namespace nomenclature.

East of Nowhere