简体   繁体   中英

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM