I am new to visual studio and developing universal windows applications. My program throws an exception when I click a UI button that should display location information on click. It is a UWP. The location access is turned on from the package manifest. The code looks like this:
private async void myButton_Click(object sender, RoutedEventArgs e)
{
try
{
var geoLocator = new Geolocator();
geoLocator.DesiredAccuracy = PositionAccuracy.High;
Geoposition positionInfo = await geoLocator.GetGeopositionAsync();
string latitude = "Latitude: " + positionInfo.Coordinate.Point.Position.Latitude.ToString();
string longitude = "Longitude: " + positionInfo.Coordinate.Point.Position.Longitude.ToString();
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
Debug.WriteLine(ex.StackTrace);
}
}
The exception stacktrace is as below:
Exception thrown: 'System.Exception' in mscorlib.ni.dll Exception from HRESULT: 0x80072EE7 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter
1.GetResult() at HelloLocation.MainPage.<getBtn_Click>d__1.MoveNext() Exception thrown: 'System.Exception' in mscorlib.ni.dll Exception from HRESULT: 0x80072EE7 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter
1.GetResult() at HelloLocation.MainPage.d__1.MoveNext() Exception thrown: 'System.Exception' in mscorlib.ni.dll Exception from HRESULT: 0x80072EE7 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at HelloLocation.MainPage.<getBtn_Click>d__1.MoveNext() Exception thrown: 'System.Exception' in mscorlib.ni.dll Exception from HRESULT: 0x80072EE7 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter
1.GetResult() at HelloLocation.MainPage.d__1.MoveNext() The program '[3032] hellolocation.exe' has exited with code -1 (0xffffffff).