6

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 

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

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

1
  • It is null at 'string icon =....' but debugger is not even hitting the line 'Result image = ...' and exception is being thrown Commented Feb 14, 2016 at 14:42

1 Answer 1

4

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.

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

Sign up to request clarification or add additional context in comments.

10 Comments

Appreciate your reply, now it is clear what should I be doing to handle correctly. I did as you told and when I combined the results of exceptions in output window, it boils down to this " Object reference not set to an instance of an object at TestWeather.MainPage.<Button_Click>d__1.MoveNext() " But I never implemented MoveNext() method and it is no where to be found in solution as well.
Can you post the entire stacktrace?
at TestWeather.MainPage.<Button_Click>d__1.MoveNext() That is the entire stacktrace.
thats not the stack trace... it gives the whole path of the calls.
An alternate solution is to turn on first-chance exceptions in the Debug Settings; that obviates the need to add try/catch throughout your code.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.