什么是 XAML 在未处理的异常和 app.gics 文件上生成的中断

Cod*_*221 5 c# visual-studio windows-phone win-universal-app

我是 Windows 应用程序开发新手。我正在尝试使用 x64 平台在本地计算机上执行解决方案。但每当我执行 Button_Click 事件时,我都会收到此异常

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

在 App.gics 文件中。

当调试器点击下面的变量“图标”时,我收到此异常

 private async void Button_Click(object sender, RoutedEventArgs e)
        {
            RootObject myWeather =
                await OpenWeatherMapProxy.GetWeather(20.0,30.0);

            string icon = String.Format("ms-appx:///Assets/Weather/{0}.png", myWeather.weather[0].icon);
            ResultImage.Source = new BitmapImage(new Uri(icon, UriKind.Absolute));
            ResultTextBlock.Text = myWeather.name + " - " + ((int)myWeather.main.temp).ToString() + " - " + myWeather.weather[0].description;
        }
Run Code Online (Sandbox Code Playgroud)

如果有人可以解释如何消除此异常以及 App.gics 文件是什么,那将会很有帮助。

Car*_*ine 4

App.g.i.cs是一个自动生成的文件,它在该位置中断,因为您没有在代码中正确处理异常。

private async void Button_Click(object sender, RoutedEventArgs e)
{
    try{

    RootObject myWeather =
        await OpenWeatherMapProxy.GetWeather(20.0,30.0);

    string icon = String.Format("ms-appx:///Assets/Weather/{0}.png", myWeather.weather[0].icon);
    ResultImage.Source = new BitmapImage(new Uri(icon, UriKind.Absolute));
    ResultTextBlock.Text = myWeather.name + " - " + ((int)myWeather.main.temp).ToString() + " - " + myWeather.weather[0].description;

    }
    catch(Exception ex)
    {
       Debug.WriteLine(ex.Message);
       Debug.WriteLine(ex.StackTrace);
    }
}
Run Code Online (Sandbox Code Playgroud)

当应用程序运行时转到“输出”窗口并查看异常详细信息,您可能会找到答案。

最有可能的异常是由于未能获取数据而导致的myWeathermyWeather.weather[0]为空。OpenWeatherMapProxy.GetWeather