views:

179

answers:

1

Hi.

I'm having a problem with conflicting namespaces and code that gets autogenerated by the forms designer in Visual Studio 2008. I have search many forums and different documentation, but have not been able to find any solution to this problem.

I have one assembly called Foo.dll with the following namespace/code:

namespace Foobar.System
{
    public class MySystemClass() { }
}

Then, I have another assembly which contains som commonly used forms:

namespace Foobar.MyCommonForms
{
    public class MyForm : System.Windows.Forms.Form
    {
        public void SomeMethod()
        {
            var systemclass = new Foobar.System.MySystemClass();
        }
    }
}

Here, the compilers display the following error: Type or namespace 'Windows' is not part of namespace 'Foobar.System'. Obviously, the compiler tries to look for the class System.Windows.Forms.Form in namespace Foobar.System.Windows.Forms!

I have been able to solve this by using the alias 'x' instead of 'global' when referencing to the assembly Foo.dll, and declaring 'extern alias x' in my code files, and put 'x::' in front of every reference to types and classes in the namespace Foobar.System. The code compiles.

But it seems that the forms designer don't recognise this, and gives me an error when trying to display the form. This, again, can be solved by manually putting 'global::' in front of every reference to classes in System.Windows.Forms (e.g. global::System.Windows.Forms.Button), but every time chances are made to the form, the code is automaticaly re-generated, and the 'global::' part is removed.

So, the question is: Is there a way to make the forms designer aware of the alias 'x' that is used to reference my assembly Foo.dll, or is there another, better solution to this? Renaming the namespace Foobar.System to something else is just too much work.

A: 

There's no way around this, from what I can tell.

The popular refactoring tools such as Resharper or Refactor! both include the ability to globally rename a namespace. I'd seriously consider using those.

Jeremy McGee