什么是 XAML 在未处理的异常和 app.g.i.cs 文件上生成的中断 [英] What is XAML generated break on unhandled exception and app.g.i.cs file

查看:33
本文介绍了什么是 XAML 在未处理的异常和 app.g.i.cs 文件上生成的中断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am new to windows app development. I am trying to execute a solution on my local machine using x64 platform. But whenever I execute a Buttom_Click event I am getting this exception

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

在 App.g.i.cs 文件中.

in App.g.i.cs file.

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

I am getting this exception when debugger hits the variable 'icon' below

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

如果有人能解释如何摆脱这个异常以及什么是 App.g.i.cs 文件,那将会很有帮助.

It would be helpful if anyone can explain how to get rid of this exception and what is App.g.i.cs file.

推荐答案

App.gics 是一个自动生成的文件,它在那个位置被破坏,因为你没有正确处理异常您的代码.

App.g.i.cs is an auto genearated file, and its breaking at that location because you haven't handled the exception properly in your code.

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

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

Go to the Output window when the application is running and go through the exception detail, you might find the answer.

最有可能的异常是由 myWeathermyWeather.weather[0] 为 null 引起的,因为 OpenWeatherMapProxy.GetWeather 未能获取数据.

Mostlikely exception is causeded by myWeather or myWeather.weather[0] being null because OpenWeatherMapProxy.GetWeather failed to fetch the data.

这篇关于什么是 XAML 在未处理的异常和 app.g.i.cs 文件上生成的中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆