Reputation: 48686
I know I am overlooking something really simple here.
I am using Visual Studio 2008 and created an ASP.NET 3.5 project and solution. I added another project to my solution, a class library. I added a reference to my class library. Now when I click on the properties of my class library, the Default Namespace is set to "HRCommon", which is correct.
Now for some reason, from my ASP.NET application, it's automatically importing the HRCommon namespace. So when I want to reference a class out of my class library, I just need to type the classname. I want to have to specify the whole name, like HRCommon.<ClassName>
instead of just <ClassName>
.
Anyone tell me what I'm overlooking here? The language is C#, btw.
Upvotes: 1
Views: 1811
Reputation: 887469
What namespace is your ASP .Net code in?
It's probably inside of HRCommon.
If you write code in a nested namespace, it will automatically import all parent namespaces (eg, code in System.Windows.Forms
doesn't need to import System.Windows
and System
)
To prevent this, move either the library or the ASP .Net project to a different namespace.
Alternatively, you might not have namespace
statements in the library.
The Default Namespace option in VS is only used to generate the namespace
block in new C# source. EDIT: To clarify, the Default Namespace setting is not used by the compiler at all. It's only used by the Visual Studio to automatically insert namespace
blocks in new source files.
Check the source files in the library and make sure that all of the classes are defined inside of the namespace HRCommon
.
For example:
namespace HRCommon {
public class MyClass {
//...
}
}
Upvotes: 2
Reputation: 887469
EDIT: The problem is that you didn't put the library code in a namespace (as described in the lower half of my first answer); I'm leaving this here for reference.
Check that HRCommon
isn't in the list of default namespaces in Web.config. (It probably isn't, but no harm checking).
Specifically,look in system.web/pages/namespaces
. If your Web.config doesn't have a namespaces
element (the default one doesn't), this is obviously not the issue.
Upvotes: 0