为什么没有 ConfigurationManager?

Why dont have ConfigurationManager?

我尝试使用 ConfigurationManager,起初 System.Configuration 没有,我想知道为什么。

经过一些尝试,在包含参考后 System.Configuration 现在它显示了。

那么我如何在没有参考的情况下使用 System.Configuration?但需要引用才能使用 System.Configuration.ConfigurationManager

任何程序集都可以导出任何命名空间。

MyFoo.dll 可以在命名空间内定义类型,例如 System.Configuration.VeryImportant.Type,这意味着如果您引用 MyFoo.dll System.Configuration 是一个有效的命名空间,即使 ConfigurationManager 类型在 System.Configuration.dll 程序集中定义。

默认包含其他程序集,其中可能包含 System.Configuation 作为导出的命名空间。

这是因为 命名空间 被分割成几个 程序集

您可能已经从 mscorlib.dll 程序集或类似的核心 dll

中获取了原始的 System.Configuration 命名空间

在 .net1.0 和 1.1 中,命名空间 System.Configuration 在 System.dll.
下 自 .net2.0 以来,有一个新程序集 - System.Configuration.dll.

回到我们不得不使用 ConfigurationSettings 的日子,它在 System.dll 程序集中,现在已经过时了。
现在,我们在 System.Configuration.dll 程序集中使用 ConfigurationManager 和它。

所以,您得到 System.Configuration 的原因可能是因为您引用的是默认包含在 winforms 应用程序中的 System.dll