c# - 程序集访问

标签 c# .net

如果您的程序集身份/命名空间为 Library.Testing . 然后您创建了另一个程序集,其身份/ namespace 为 Library.Testing.One Library.Testing.One项目引用 Library.Testing .

为什么你必须使用 using Library.Testing;在你的类里面 Library.Testing.One访问 Library.Testing 中的任何内容?

示例 1:

using System;

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

这不起作用我得到两个异常

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?)

例子2:

using System;
using Library.Testing;

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

这行得通!

最佳答案

Library.Testing.One 添加“using”不会自动将 LibraryLibrary.Testing 中的所有内容纳入范围。命名空间似乎是分层的这一事实可能是导致您混淆的原因。

例如,考虑将 using System.Data.SqlClient 添加到文件中。这不会自动将 SystemSystem.Data 中的所有内容都纳入范围。

关于c# - 程序集访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3589046/

相关文章:

c# - 通过 GET 将数组传递给 WCF 服务

c# - Linq 加入错误

c# - VS2010安装项目升级及快捷键

mysql - 使用 FirstOrDefault 与 ToArray 的 LINQ 查询

.net - 从wpf打印的xps文档-太短,纸张尺寸奇怪吗?

c# - 在日期时间 c# 中格式化字符串以插入 MYSQL 日期时间列

c# - 如果在接口(interface)上定义属性,xVal 会起作用吗?

c# - IIS APPPOOL\MyAppPool 无法登录到我的 SQL Server 数据库

.net - Oracle 的 EF 提供程序

c# - 何时何地使用 LINQ to Objects?