views:

70

answers:

1

When my Wpf app starts up I get a BindingFailureException in Settings.Designer.cs

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

With the following message:

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.

In My MainWindow code behind I am doing the following on 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( ));
        }

Also in window_closing

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

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

Which also throws the same exception. Why am I get an exception accessing the Properties.Settings?

+1  A: 

That exception is not so unusual in my experience. What is unusual is that the exception is (apparently) unhandled in your situation. Usually, (again in my experience) that exception is silently caught and handled by some other mechanism.

You are not, by any chance, running this in the VS debugger with 'break when an exception is thrown' are you? That setting is under Debug -> Exceptions..., by the way.

Daniel Pratt
Yes I am. This is likely to be the issue.
Maslow
I had inner code modifying the collection I was iterating around this same area and thought it was related to the binding failure exception.
Maslow