I'm seeing some weird behavior with namespace resolution and wonder if
anyone has an explanation. I have a solution with two C# class library
projects, A & B. A depends on B. Each project has one class. The Foo class
in project B does nothing interesting. The Bar class in project A tries to
create an instance of Foo in its ctor. This fails with what appears to be a
namespace resolution problem. Sample code below:
---------------------------------------------
Project A:
using System;
namespace A.B.C
{
public class Bar
{
public Bar()
{
B.C.Foo foo = new B.C.Foo();
}
}
}
---------------------------------------------
Project B:
using System;
namespace B.C
{
public class Foo
{
public int x = 1;
public Foo() {}
}
}
---------------------------------------------
When building this with VS.2003 (and VS.2002 for that matter), the following
error results:
Bar.cs(9,8): error CS0234: The type or namespace name 'Foo' does not exist
in the class or namespace 'A.B.C' (are you missing an assembly reference?)
I tried the both IDE and csc.exe on its own with the same results.
Note that I do have a project reference to project B in project A. It seems
that the namespace A.B.C (in class Bar) overrides the namespace B.C (in
class Foo). But I thought namespaces were resolved using their full name not
partial names.
Also, I have to create Foo the way I'm doing it (ie. prefixed with its
namespace) because in reality the name "Foo" is "Attribute" which conflicts
with an object in the System namespace :)
Renaming the Foo namespace is a possibility but I prefer not to do it if
there is a better solution (or at least an explanation as to what's causing
the problem). And using a alias on the B.C namespace is also a possibility
but since every client will have to do this, it seems like an inelegant
solution.
Any insights appreciated.
-Peter
===================================
This list is hosted by DevelopMentor� http://www.develop.com
NEW! ASP.NET courses you may be interested in:
2 Days of ASP.NET, 29 Sept 2003, in Redmond
http://www.develop.com/courses/2daspdotnet
Guerrilla ASP.NET, 13 Oct 2003, in Boston
http://www.develop.com/courses/gaspdotnet
View archives and manage your subscription(s) at http://discuss.develop.com