2010-08-13 38 views
0

當我的WPF應用程序啓動時我得到了一個Settings.Designer.cs BindingFailureExceptionWPF Properties.Settings上推出拋出異常,並關閉

[global::System.Configuration.UserScopedSettingAttribute()] 
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 
    public global::System.Collections.Specialized.StringCollection Projects { 
     get { 
      return ((global::System.Collections.Specialized.StringCollection)(this["Projects"])); 
     } 
     set { 
      this["Projects"] = value; 
     } 
    } 

以下消息:

The assembly with display name 'System.XmlSerializers' failed to load in the 'LoadFrom' binding context of the AppDomain with ID 1. The cause of the failure was: System.IO.FileNotFoundException: Could not load file or assembly 'System.XmlSerializers, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified. 

在我主窗口後面的代碼我這樣做對window_loaded如下:

try 
     { 
      if (Properties.Settings.Default.Projects==null) 
      Properties.Settings.Default.Projects=new StringCollection(); 
     var removalList = new List<string>(); 
     foreach (string project in Properties.Settings.Default.Projects) 
     { 
      if (System.IO.File.Exists(project)) 
       OpenProject(project); 
      else 
      { 
       removalList.Add(project); 
      } 

     } 
     foreach (string missingProject in removalList) //so that we are not removing an item while iterating 
     { 
      Properties.Settings.Default.Projects.Remove(missingProject); 
     } 
      } 
     catch (Exception ex) 
     { 
      Debug.WriteLine(ex.ToString()); 
     } 

另外在window_closing

try 
      { 
       //TODO: save prompt 
       Properties.Settings.Default.Save(); 
      } 
      catch (Exception ex) 
      { 

       Debug.WriteLine(ex.ToString()); 
      } 

其中也會引發相同的異常。爲什麼我得到一個異常訪問Properties.Settings

回答

2

這個例外在我的經驗中並不是那麼不尋常。什麼不尋常的是,異常是(顯然)未處理你的情況。通常(再次以我的經驗),異常被一些其他機制默默地捕獲和處理。

您是不是在VS調試器中運行了這個函數,並且在'拋出異常時拋出'這個問題呢?順便說一下,該設置位於Debug - > Exceptions ...下。

+0

是的,我。這可能是問題所在。 – Maslow 2010-08-13 21:29:28

+0

我的內部代碼修改了我在同一區域迭代的集合,並認爲它與綁定失敗異常有關。 – Maslow 2010-08-13 21:34:24