2010-08-13 4 views
0

Lorsque mon application WPF démarre je reçois un BindingFailureException dans Settings.Designer.csWPF Properties.Settings lance exception au lancement et à proximité

[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; 
     } 
    } 

avec le message suivant:

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. 

Mon Code MainWindow derrière je fais ce qui suit sur 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()); 
     } 

également dans window_closing

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

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

Qui lance également la même exception. Pourquoi est-ce que je reçois une exception en accédant au Properties.Settings?

Répondre

2

Cette exception n'est pas si inhabituelle dans mon expérience. Qu'est-ce est inhabituel est que l'exception est (apparemment) non gérée dans votre situation. Habituellement, (toujours selon mon expérience), cette exception est capturée silencieusement et gérée par un autre mécanisme.

Vous n'êtes pas, par hasard, en cours d'exécution dans le débogueur VS avec «casser quand une exception est levée» êtes-vous? Ce paramètre est sous Debug -> Exceptions ..., soit dit en passant.

+0

Oui, je suis. C'est probablement le problème. – Maslow

+0

J'avais un code interne qui modifiait la collection que j'écrivais autour de cette même zone et je pensais que c'était lié à l'exception d'échec de liaison. – Maslow

Questions connexes