views:

24

answers:

2

I have a solution that contains many projects all using the same root namespace. No code files explicitly name a namespace. So lets say the root namespace is ExampleRootNamespace.

Now a problem comes into play when I want to add an explicitly named namespace to one of the code files I am working on. I want to be able to isolate this code from the rest of the assembly to be able to run FxCop against it. So I add something like Namespace Interfaces.CSV to the code file.

This causes any code that references this assembly to need to say Imports ExampleRootNamespace.Interfaces.CSV. So far so good. I can even run FxCop against the assembly. The problem now is that in other assemblies I cannot say any longer things like:

Public class frmInputBoolean Inherits
 ExampleRootNameSpace.frmFormTemplate

Visual Studio is now asking me to rename the namespace to:

Public class frmInputBoolean Inherits
     Global.ExampleRootNameSpace.frmFormTemplate

There are hundreds of errors related to this. So my questions are:

1) Why would basically naming a namespace under the root for the first time cause issues with the program?

2) Are there any workarounds to this issue without renaming?

I also want to add that with regards to ExampleRootNamespace.Interfaces.CSV I am not referencing this anywhere in the codebase. I'm currently just referencing it from a unit test project. So I don't see why adding this namespace causes an issue.

+1  A: 

In C# try utilizing the USING operator with your namespace.

using ExampleRootNamespace = newExampleRootNamespace;

On the ones that have the global issue.

sadly, I do not believe an easy solution exists for you in VB.NET

Michael Eakins
In Vb it would be Imports. I suggest "Imports ExampleRootNamespace = Global.ExampleRootNamespace" http://msdn.microsoft.com/en-us/library/7f38zh8x(VS.71).aspx
MarkJ
This won't work as you can't use "Global" in the imports statement. See my own answer to this thread. Thanks for the suggestion Meakins and MarkJ. It did help get the code to compile.
Matt Spinelli
+1  A: 

Well, it appears this may be a bug in Visual Studio 2008. As the code has not changed but the problem with the required Global prefix is no longer there.

I say this because I checked out one of the offending code files and tried to add (as Meakins suggested):

Imports ExampleRootNamespace = Global.ExampleRootNamespace

When I did this two things happened.

1) The error highlighting and error correction suggestions were removed and ExampleRootNamespace was recognized by Visual Studio. Also the code now compiles.

2) Imports ExampleRootNamespace = Global.ExampleRootNamespace is not valid because of the use of Global in the imports statement. Visual studio says: "'Global' not allowed in this context; identifier expected." This Means that this line of code will not compile. So I removed it all together. Oddly enough despite it not being there (and thus the code returning to as before) there are no more errors.

I also restarted visual studio (but after doing the above). This is quite odd if you ask me!

Matt Spinelli