为什么没有ConfigurationManager?

时间:2017-03-09 18:31:00

标签: c# visual-studio using

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

enter image description here

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

enter image description here

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

的参考

enter image description here

3 个答案:

答案 0 :(得分:2)

这是因为名称空间分为几个程序集

您可能从mscorlib.dll程序集或类似的核心dll获取原始System.Configuration命名空间

答案 1 :(得分:2)

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

回到我们必须使用ConfigurationSettings的日子,它位于System.dll组件中,现在已经过时了。
现在,我们正在使用ConfigurationManager及其System.Configuration.dll程序集。

因此,您获得System.Configuration的原因可能是因为您引用了winforms应用程序中默认包含的System.dll

答案 2 :(得分:1)

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

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

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