Chauncat
Chauncat

Reputation: 248

Assembly access

If you have a assembly identity/namespace of Library.Testing. Then you created another assembly with identity/namespace of Library.Testing.One Library.Testing.One project references Library.Testing.

Why is it you have to use using Library.Testing; in your classes in Library.Testing.One to access anything in Library.Testing?

Example1:

using System;

namespace Library.Testing.One
{
    // 'Library.Testing' is a reference in this assembly
    public class foo : Library.Testing.BooBase
   {
   }
}

This does not work I get two exception

Warning 1 Load of property 'RootNamespace' failed. The string for the root namespace must be a valid identifier. Error 2 The type or namespace name 'BooBase' does not exist in the namespace 'Library.Testing.One.Library.Testing' (are you missing an assembly reference?)

Example2:

using System;
using Library.Testing;

namespace Library.Testing.One
{
    // 'Library.Testing' is a reference in this assembly
    public class foo : Library.Testing.BooBase
   {
   }
}

This works!

Upvotes: 2

Views: 3473

Answers (1)

Rob
Rob

Reputation: 45771

Adding a "using" for Library.Testing.One does not automatically bring everything in Library and Library.Testing into scope. The fact that the namespaces appear to be hierarchical is probably what's leading to your confusion.

Think of, for example, adding using System.Data.SqlClient to a file. That doesn't automatically bring everything in System and System.Data into scope.

Upvotes: 1

Related Questions