views:

318

answers:

2

I'm getting a compiler error saying that "Acme.Business.User" is not defined.

I have a class library project called "Acme.Business" that has "Acme.Business" as the assembly name and root namespace as well. None of the classes use the "Namespace" keyword, so they all should exist in the namespace "Acme.Business".

I also have a class library project called "Acme.Web" that has a project reference to "Acme.Business". Again "Acme.Web" is the project name, assembly name, and root namespace.

Here's the weird part. If I add a class to "Acme.Web" I can type "Imports Acme." at the top and see both namespaces appear in intellisense like you'd expect, but if I try to do "Dim x as New Acme.Business.User" then "Business" doesn't show up in intellisense and I get an error saying "Acme.Business.User" is not defined.

I can't see what I'm doing wrong! Please help. Thanks.

+1  A: 

I think you may be misunderstanding how project default namespaces work. The default namespace is a project file setting that simply tells Visual Studio what namespace to add to each file when you add a new class file to the project. If you have removed all of these namespaces from the code files then your types do not exist in that namespace.

This means that all of your types in the Acme.Business assembly live in the global namespace which is probably not what you want. In order to get the desired behavior you will need to add the namespaces back into your code files as that is the only way the compiler will create type names with that namespace.

Andrew Hare
Thanks for responding. I don't think that's the case. Maybe with C#, but with VB.NET if I add a new class it doesn't stub in the namespace. Also, referring to types in Acme.Business works fine from within my code-behind pages, so I think Acme.Business is ok, but Acme.Web has to change.
adam0101
Well, you're right that they're in the global namespace, but they're still within the specified root namespace under that because I get to them like this: "Dim x as new Global.Acme.Business.User". I don't know what changed because I never had to specify the namespace in the code before and it worked
adam0101
A: 

OK, I figured out that the behavior I was seeing was because I was declaring namespaces within the code in Acme.Web the way I was used to in C# which is to fully qualify it, ie. Namespace Acme.Web.UI.WebControls. I didn't realize that in VB.NET it's building on top of what was specified for the root namespace. I removed the portion that was specified in the "root namespace" setting of my project and it started working. So my namespaces in code for Acme.Web now look like Namespace UI.WebControls.

adam0101