2009-11-02 94 views
3

我根本無法獲取Visual Studio 2005來找到System.Configuration.ConfigurationManager類。下面是代碼:無法獲得對ConfigurationManager的引用

using System.Configuration; 

... 

x = ConfigurationSettings.AppSettings["MySetting"] 
// The name 'ConfigurationManager' does not exist in the current context 

x = System.Configuration.ConfigurationManager.AppSettings["MySetting"] 
// The type or namespace name 'ConfigurationManager' does not exist in the 
// namespace 'System.Configuration' (are you missing an assembly reference?) 

我絕對,積極在該項目中,以System.Configuration參考,它肯定是在正確的項目。該DLL是2.0.0.0版,運行時版本是2.0.50727 - 與其他所有版本完全相同。我嘗試刪除引用並重新添加它。奇怪的是,當它顯示在項目的參考文件夾中時,它顯示爲'System.configuration' - 小寫'c'。

Visual Studio可以找到System.Configuration.ConfigurationSettings類,除了它已過時的警告外沒有任何問題。該項目是一個Web項目,代碼位於WebControl的代碼隱藏之中。

任何想法發生了什麼?

回答

2

參考中的小寫字母「c」是正常的。你的代碼對我來說很好。我想知道您向我們展示的片段之外是否存在問題。嘗試構建一個全新的解決方案,只需調用其參考配置即可。證明這是有效的。

+0

感謝您的建議。事實證明,.NET運行時全部搞砸了,因爲它安裝的帳戶沒有足夠的權限。完全重新安裝一個'上帝'帳戶解決了這個問題。很奇怪。 – TallGuy 2009-11-04 00:07:12

13

您是否添加了對System Assembly System.Configuration.dll的引用?

IIRC AppSettings位於BCL核心庫中,2.0 ConfigurationManager在單獨的程序集中。

+0

我有完全相同的問題。 VS2005似乎知道System.Configuration命名空間的事實讓我感到不快。一旦我添加了對System.Configuration.dll的引用,ConfigurationManager就可以使用了。謝謝! – 2013-07-22 03:51:51