LocalSettings breaking on unhandled XAML exception

2019-09-07 06:16发布

问题:

I am having some trouble figuring out why, when I try to define LocalSettings to a field so I can access it from multiple methods, it performs a break during a debug run within App.g.i.cs at the following code:

#if DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
            UnhandledException += (sender, e) =>
            {
                if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();
            };
#endif

Here is my actual class:

public sealed partial class MainPage : Page
{
    private ApplicationDataContainer _localSettings;

    public MainPage()
    {
        this.InitializeComponent();
        _localSettings = ApplicationData.Current.LocalSettings;
    }
}

I have tried wrapping it in a try/catch statement, yet that did not catch the exception, so I have no idea what is causing this.

I have also tried directly copying the code from the LocalSettings page linked above, which produces the same problem as my code.

Does anyone know why this is happening, and preferably also where I can find a solution?