xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.62k stars 1.87k forks source link

[Bug] UWP app crash when starting in airplane mode with a map control #5929

Open DennisWelu opened 5 years ago

DennisWelu commented 5 years ago

Description

A UWP app started in airplane mode crashes if a map control is present.

Steps to Reproduce

  1. Find a UWP project having a map control with IsShowingUser="True"
  2. Build it and run it while online. See that it works.
  3. Turn airplane mode on and run it again. See that it crashes.

Expected Behavior

No crash

Actual Behavior

Crash with unhandled exception in the UWP map renderer: EXCEPTION:

System.Exception : Exception from HRESULT: 0x80072EE7   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Xamarin.Forms.Maps.UWP.MapRenderer.<UpdateIsShowingUser>d__11.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Xamarin.Forms.Maps.UWP.MapRenderer.<OnElementChanged>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.<ThrowAsync>b__6_0(Object state)
   at System.Threading.WinRTSynchronizationContextBase.Invoker.InvokeCore()

Basic Information

Reproduction Link

https://github.com/xamarin/xamarin-forms-samples/tree/master/WorkingWithMaps

The HRESULT error code is explained here, having to do with server name resolution: https://ru.stackoverflow.com/a/915097

jcmanke commented 5 years ago

Do you having the IsShowingUser property set to true? Does it still crash if you switch it to false?

DennisWelu commented 5 years ago

@jcmanke Yes good point, I've updated the description to specify that IsShowingUser must be set to "True". When set to false (or left as the default) then the problem does not occur.

jcmanke commented 5 years ago

This seems like the typical problem with IsShowingUser, you must have location permission and the device's location services enabled. Most, if not all, UWP devices do not have GPS chips, so they use network signals to determine your location. Airplane mode == no network == no location.

Side note I discovered trying to reproduce this: the system will ask for location permissions the first time you set IsShowingUser true, but if you deny permission it will crash the app and there is no recovering unless you turn it on from the system settings.