Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

Problem with namespaces and the IDE

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
TheSilverHammer - 24 Mar 2008 20:15 GMT
Maybe I am not using namespaces correctly, but in general, my project has one
namespace.   The problem is that the IDE keeps fighting me with them, as in
it tries to 'help' by adding a bunch of namespace qualifies to things it
should not.

My big issue right now is databinding.    My project namespace is
"AutoTerm", and I have a class AutoEmailMessage and the keeps messing up the
databinding source such:
this.autoEmailMessageBindingSource.DataSource =
typeof(AutoTerm.AutoEmailMessage);

it should be:

this.autoEmailMessageBindingSource.DataSource = typeof(AutoEmailMessage);

Because the designer.cs file for the form is in the same namespace.   Any
time I change the form, "AutoTerm." is being added back in which messes
things up.  I can't figure out how to tell it to stop doing that or how I am
supposed to correct the problem.

Other issues happen when I create sub folders, and design a new form, it
always prepends the form namespace with "AutoTerm.Subfoldername.Whatever" and
I have to edit those as well.

Is there any way to tell it to just assume it is always in the default
namespace?
Peter Duniho - 24 Mar 2008 20:29 GMT
> Maybe I am not using namespaces correctly, but in general, my project  
> has one
> namespace.   The problem is that the IDE keeps fighting me with them, as  
> in
> it tries to 'help' by adding a bunch of namespace qualifies to things it
> should not.

Why shouldn't it?  In what context is it adding the qualification when you  
feel it's incorrect and problematic to do so?  Why is it incorrect and  
problematic to do so in that context?

> My big issue right now is databinding.    My project namespace is
> "AutoTerm", and I have a class AutoEmailMessage and the keeps messing up  
[quoted text clipped - 6 lines]
>
> this.autoEmailMessageBindingSource.DataSource = typeof(AutoEmailMessage);

Why?  What's the difference, other than a few additional characters?

> Because the designer.cs file for the form is in the same namespace.   Any
> time I change the form, "AutoTerm." is being added back in which messes
> things up.  I can't figure out how to tell it to stop doing that or how  
> I am
> supposed to correct the problem.

Is the code you posted being generated in the *.Designer.cs file?  If so,  
then just leave it alone.  You can't edit that file reliably, because the  
Designer will _always_ modify it the next time you edit the form using the  
Designer.  As long as "AutoTerm.AutoEmailMessage" is equivalent to  
"AutoEmailMessage" in that context, I don't see anything wrong with what  
the Designer is doing.

Pete
Jon Skeet [C# MVP] - 24 Mar 2008 20:33 GMT
> Maybe I am not using namespaces correctly, but in general, my project has one
> namespace.   The problem is that the IDE keeps fighting me with them, as in
[quoted text clipped - 15 lines]
> things up.  I can't figure out how to tell it to stop doing that or how I am
> supposed to correct the problem.

I don't see how it's a problem. If the class can be resolved either way
and this is in a designer file, why is it an issue to qualify the class
within the "typeof"?

> Other issues happen when I create sub folders, and design a new form, it
> always prepends the form namespace with "AutoTerm.Subfoldername.Whatever" and
> I have to edit those as well.

Yes, that's deliberate and helpful. Why are you creating subfolders
without wanting to create a new namespace?

> Is there any way to tell it to just assume it is always in the default
> namespace?

You could edit the templates for classes etc. I don't know much about
that side of things, but I'm sure it's possible.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

TheSilverHammer - 24 Mar 2008 21:28 GMT
it is a problem because it doesn't compile.

The implied namespace is AutoTerm, so when it puts AutoTerm.AutoEmailMessage
it *really* is looking for AutoTerm.AutoTerm.AutoEmailMessage.    The
compiler complains that there is no "AutoTerm.AutoTerm" which is true.

With reguards to everything else, I do not like them because they also do
not compile right.    Make a folder, make a new form in that folder and
suddenly the designer IDE pukes until you delete the extra namespace stuff
and then it all works again.

> > Maybe I am not using namespaces correctly, but in general, my project has one
> > namespace.   The problem is that the IDE keeps fighting me with them, as in
[quoted text clipped - 32 lines]
> You could edit the templates for classes etc. I don't know much about
> that side of things, but I'm sure it's possible.
Jon Skeet [C# MVP] - 24 Mar 2008 22:42 GMT
> it is a problem because it doesn't compile.
>
> The implied namespace is AutoTerm, so when it puts AutoTerm.AutoEmailMessage
> it *really* is looking for AutoTerm.AutoTerm.AutoEmailMessage.

No, it's not. There's no problem explicitly using a namespace. For
example:

using System;

namespace Foo
{
   class Bar
   {
   }
   
   class Test
   {
       static void Main()
       {
           Foo.Bar x = new Foo.Bar();
       }
   }
}

> The compiler complains that there is no "AutoTerm.AutoTerm" which is true.

My guess is that you've got a *class* called AutoTerm as well. Let's
change my example slightly:

using System;

namespace Foo
{
   // This is new
   class Foo
   {
   }
   
   class Bar
   {
   }
   
   class Test
   {
       static void Main()
       {
           Foo.Bar x = new Foo.Bar();
       }
   }
}

Now it fails to compile. Basically, using a class with the same name as
a namespace introduces quite a few opportunities for ambiguity - best
to avoid it. Some later designers use global::Namespace.TypeName I
believe, in order to avoid this problem, admittedly, but it looks like
that's not the case for you.

> With reguards to everything else, I do not like them because they also do
> not compile right.    Make a folder, make a new form in that folder and
> suddenly the designer IDE pukes until you delete the extra namespace stuff
> and then it all works again.

Again, I suspect that's because you've got something "odd" in your
situation. It works fine normally.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

TheSilverHammer - 25 Mar 2008 17:51 GMT
Yeah there is a class called AutoTerm, the one the project created when I
chose the name "AutoTerm" for the project.

> > it is a problem because it doesn't compile.
> >
[quoted text clipped - 61 lines]
> Again, I suspect that's because you've got something "odd" in your
> situation. It works fine normally.
Jon Skeet [C# MVP] - 25 Mar 2008 17:56 GMT
> Yeah there is a class called AutoTerm, the one the project created when I
> chose the name "AutoTerm" for the project.

That sounds unlikely to me. Normally:

o If you create a Windows Forms app, it creates Form1.cs and
Program.cs.

o If you create a class library, it creates Class1.cs

o If you create a console app, it creates Program.cs (IIRC)

See if you can reproduce it...

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

Ignacio Machin ( .NET/ C# MVP ) - 25 Mar 2008 18:46 GMT
On Mar 25, 12:51 pm, TheSilverHammer
<TheSilverHam...@discussions.microsoft.com> wrote:
> Yeah there is a class called AutoTerm, the one the project created when I
> chose the name "AutoTerm" for the project.

That is not the default. It does create a namespace with the same
name, but the class is named Form1 and there is also a  Program.cs

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.