Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Namespaces, aliases and Visual Studio Forms Designer

Namespaces, aliases and Visual Studio Forms Designer

Scheduled Pinned Locked Moved C#
helpquestioncsharpvisual-studio
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Agent25
    wrote on last edited by
    #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.

    F D U 3 Replies Last reply
    0
    • A Agent25

      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.

      F Offline
      F Offline
      freakyit
      wrote on last edited by
      #2

      hi, this sounds realy heavy to me, but i think you can change the namespace at the project properties to solve the problem. maybe all namespaces in classes will be renamed (think i saw some like that).. i think the problem is that the projects name namespace is written in has the same name as the assembly namespace so the windows forms designer implicit thinks that the System namespace comes from YOUR assembly not from microsoft.. i might think totaly wrong but i thought i try to help you with an idea :) greetz

      1 Reply Last reply
      0
      • A Agent25

        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.

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        You've got something seriously screwed up in your project. The compiler cannot look for System.Windows.Forms in your namespace. I don't know what to tell you because I can't even replicate the problem in a test project with what you've posted. What are the namespace properties of the project? What namespaces are you importing at the top of the code for each of these??

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007, 2008
        But no longer in 2009...

        1 Reply Last reply
        0
        • A Agent25

          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.

          U Offline
          U Offline
          User 2183100
          wrote on last edited by
          #4

          I've run into this before. You are correct in that the compiler is looking in Foobar.System.Windows.Forms because you named your namespace 'System'. The local namespace 'System' overrides the global namespace 'System'. I do not know how to get around this. In my case I chose not to name my namespace 'System' but instead named it 'Foundation'. I just wanted to let everyone know that therei s nothing messed up with your project.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups