0

当我的 Wpf 应用程序启动时,我在 Settings.Designer.cs 中收到 BindingFailureException

[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.

在我背后的 MainWindow 代码中,我正在执行以下操作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?

4

1 回答 1

2

根据我的经验,这个例外并不少见。不同寻常的是,在您的情况下(显然)未处理异常。通常,(再次根据我的经验)该异常会被其他机制静默捕获和处理。

您绝对不会在 VS 调试器中使用“抛出异常时中断”来运行它,是吗?顺便说一句,该设置位于 Debug -> Exceptions... 下。

于 2010-08-13T20:55:26.470 回答