Reputation: 47733
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?
Upvotes: 0
Views: 1377
Reputation: 1396
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.
Upvotes: 0
Reputation: 105009
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.
Upvotes: 1
Reputation: 14111
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.
Upvotes: 6
Reputation: 1499740
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?
Upvotes: 3