3

if I don't put a namespace in my classes (vs.net 2008), which namespace do my classes get built under?

update Its strange, when I add a namespace I can't seem to reference the classes methods from my user control.

If I explicitly set a namespace, and add a 'using ...' in my control, I still can't see it!

How can this be?

 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Configuration; /// <summary> /// Summary description for Globals /// </summary> public class Globals { public Globals() { } public static string ConnectionString { get { return ConfigurationManager.ConnectionStrings["MyDb"].ConnectionString; } } } 

My control:

using System; using System.Data; using System.Data.SqlClient; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class MyStats : System.Web.UI.UserControl { protected void Page_Load(object sender, EventArgs e) { //etc. 
10
  • Is your class in a separate project from the user control or are they in the same project? Commented Apr 3, 2009 at 19:49
  • Also can you post some code - that may help us figure out what is going on. Commented Apr 3, 2009 at 19:52
  • Ok I posted some code, I had a namespace in the globals class before but it still didn't work when I referenced it in my control. Commented Apr 3, 2009 at 20:02
  • Do you have any compilation errors at all? Commented Apr 3, 2009 at 20:09
  • So if you use the type as if intellisense were working it compiles fine? Is it only intellisense that seems to be broken? Commented Apr 3, 2009 at 20:16

2 Answers 2

4

If you do not provide a namespace then your type has no namespace. Remember that namespaces don't have any meaning post-compile. They simply get appended to the beginning of you type's name to create a longer name that has a greater probability of being unique.

Edit: I think that you may have two separate assemblies and one ought to be referencing the other but it is not. If two projects are in a single solution then the class viewer will show all types from all projects but that does not necessarily mean that ProjectA references ProjectB. In order to use the types from ProjectB in ProjectA you need to ensure that a project reference exists.

Sign up to request clarification or add additional context in comments.

1 Comment

"...then your type has no namespace" Not quite, they are placed in the global namespace msdn.microsoft.com/en-gb/library/z2kcy19k.aspx
1

as you said, that class will not have any namespace, It will be accessible without a using clause.

Namespaces is a feature for putting order on your classes, by classifying, mostly according to their funcionality

EDIT

According to your update, i think your "global" class maybe putting trouble because of the global:: clause... would you mind to change the name of the class just to see if it works?

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.