幾天前,我的 Live Writer 不能使用了,每次顯示 Splash Screen 就顯示錯誤報表,說未捕獲的 NullReferenceException,使用 VS2005 調試也看不出什麼東西。當時估計可能是什麼本地配置出問題。因為我把 Live Writer Copy 到 VMWare 中的系統是可以正常使用的。無果,只好在虛擬機器中使用 Live Writer,真夠重量級。
然後在今天想使用 NetMassDownloader 下載 .Net 原始碼,結果依然是在啟動後拋出異常:
未處理的異常: System.Configuration.ConfigurationErrorsException: 配置節“connectionStrings”具有意外的聲明。 在 System.Configuration.ConfigurationManager.get_ConnectionStrings() 在 System.Configuration.PrivilegedConfigurationManager.get_ConnectionStrings() 在 System.Configuration.LocalFileSettingsProvider.GetPropertyValues(SettingsContext context, SettingsPropertyCollection properties) 在 System.Configuration.SettingsBase.GetPropertiesFromProvider(SettingsProvider provider) 在 System.Configuration.SettingsBase.GetPropertyValueByName(String propertyName) 在 System.Configuration.SettingsBase.get_Item(String propertyName) 在 System.Configuration.ApplicationSettingsBase.GetPropertyValue(String propertyName) 在 System.Configuration.ApplicationSettingsBase.get_Item(String propertyName) 在 DownloadLibrary.Properties.Settings.get_EULACookie() 位置 C:\Documents and Settings\Kusmezer\My Documents\Visual Studio 2005\Projects\Project1\DownloadLibrary\Properties\Settings.Designer.cs:行號 31 在 DownloadLibrary.Classes.Utility.GetWebClientWithCookie(Match ProxyMatch)位置 C:\Documents and Settings\Kusmezer\My Documents\Visual Studio 2005\Projects\Project1\DownloadLibrary\Classes\Utility.cs:行號 142 在 DownloadLibrary.PEParsing.PEFile.DownloadPDBFromServer(String targetPath)位置 C:\Documents and Settings\Kusmezer\My Documents\Visual Studio 2005\Projects\Project1\DownloadLibrary\Classes\PEFile\PEFile.cs:行號 142 在 NetMassDownloader.Program.ProcessFiles() 位置 C:\Documents and Settings\Kusmezer\My Documents\Visual Studio 2005\Projects\Project1\NetMassDownloader\Program.cs:行號 148 在 NetMassDownloader.Program.Main(String[] args) 位置 C:\Documents and Settings\Kusmezer\My Documents\Visual Studio 2005\Projects\Project1\NetMassDownloader\Program.cs:行號 78 |
這次有異常調用棧資訊就好說了嘛,可以判斷是讀取設定檔的問題,但是NetMassDownloader 應該不需要connectionStrings,可能是本機配置的問題。
於是祭出 Sysinternal FileMon,看下啟動時讀取過哪些檔案,經過詳細排查,發現讀取數個設定檔失敗後調用了 DW20.exe,這些設定檔包括 {NetFx20}\config\machine.config,{AppData}\user.config,{UserData}\user.config。
開啟"{NetFx20}\config\" 目錄一看,靠,machine.config 不見了!只有一個 machine.default,Copy 成 machine.config,啟動 Live Writer 和 NetMassDownloader,正常 =_=|||。
這裡記住一個經驗,.Net Runtime 是非常依賴設定檔的,如果你發現你的程式出了些莫名其妙的問題,看看,machine.config 還在不在配置目錄吧。
PS:我現在依然不明白,machine.config 到底是哪個程式刪的,我發誓,我絕對沒碰過它。