microsoft / appcenter-sdk-dotnet

Development repository for the App Center SDK for .NET platforms, including Xamarin
Other
309 stars 141 forks source link

Crash in DefaultScreenSizeProvider on app launch UWP SDK #398

Closed snrnats closed 7 years ago

snrnats commented 7 years ago

I am getting crash reports. It happens right after in-process background task is activated.

Crash log

Date/Time: 2017-08-13T18:06:26.562Z OS Version: Windows 10.0.15063.540 Report Version: 104 Exception Type: System.AggregateException Crashed Thread: 2 Application Specific Information: TaskExceptionHolder_UnhandledException (Unspecified error Windows.Graphics.Display: There is no physical display associated with the current view.) Exception Stack: unknown location SharedLibrary!+0x4a29f0 CryptoCoins.UWP!+0xfdfcc2 CryptoCoins.UWP!+0x11a0a3e CryptoCoins.UWP!+0x14431fe SharedLibrary!+0x4f7078 SharedLibrary!+0x44fb17 Microsoft.Azure.Mobile.Utils.DefaultScreenSizeProvider.<.ctor>b__5_0() System.Action.Invoke() SharedLibrary!+0x4f7205 SharedLibrary!+0x4f712c Thread 2 Crashed: 0 SharedLibrary 0x00007ffeacf829f0 System.Runtime.InteropServices.McgMarshal.ThrowOnExternalCallFailed(Int32 hr, RuntimeTypeHandle typeHnd) in f:\dd\ndp\fxcore\CoreRT\src\System.Private.Interop\src\Shared\McgMarshal.cs at 1267:13 1 CryptoCoins.UWP 0x00007ffeab50fcc2 __Interop.ComCallHelpers.Call($__ComObject __this, RuntimeTypeHandle __typeHnd, Int32 __targetIndex, Void* arg0, Void* arg1) in C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Packages\appcompile-20170810-073024-2860\AC\Temp\Ilc962331225\CryptoCoins.UWP.McgInterop\SharedStubs.g.cs at 12435:5 2 CryptoCoins.UWP 0x00007ffeab6d0a3e __Interop.ForwardComStubs.Stub_331(Void* InstParam, $__ComObject __this, $TypedEventHandler$2<$DisplayInformation,Object> handler, Int32 __targetIndex) in C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Packages\appcompile-20170810-073024-2860\AC\Temp\Ilc962331225\CryptoCoins.UWP.McgInterop\SharedStubs.g.cs at 11164:5 3 CryptoCoins.UWP 0x00007ffeab9731fe Windows.Graphics.Display.DisplayInformation.add_ColorProfileChanged($TypedEventHandler$2<$DisplayInformation,Object> handler) in C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Packages\appcompile-20170810-073024-2860\AC\Temp\Ilc962331225\CryptoCoins.UWP.McgInterop\SafeTypes.g.cs at 59034:4 4 SharedLibrary 0x00007ffeacfd7078 System.Threading.TimerCallback.Invoke(Object state) in at 0:0 5 SharedLibrary 0x00007ffeacf2fb17 System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeMarshal.NativeOrStaticEventRegistrationImpl.AddEventHandler(Void* InstParam, Func$2<__Canon,$EventRegistrationToken> addMethod, Action$1<$EventRegistrationToken> removeMethod, __Canon handler) in f:\dd\ndp\fxcore\CoreRT\src\System.Private.Interop\src\Shared\WindowsRuntimeMarshal.cs at 687:17 6 CryptoCoins.UWP 0x00007ffeab973006 Microsoft.Azure.Mobile.Utils.DefaultScreenSizeProvider.<.ctor>b__5_0() in at 0:0 7 SharedLibrary 0x00007ffeacf55838 System.Action.Invoke() in at 0:0 8 SharedLibrary 0x00007ffeacfd7205 System.Threading.Tasks.Task.InnerInvoke() in f:\dd\ndp\fxcore\CoreRT\src\System.Private.Threading\src\System\Threading\Tasks\Task.cs at 2444:17 9 SharedLibrary 0x00007ffeacfd712c System.Threading.Tasks.Task.Execute() in f:\dd\ndp\fxcore\CoreRT\src\System.Private.Threading\src\System\Threading\Tasks\Task.cs at 2286:17 Binary Images: 0x00007ffeacae0000 - 0x00007ffead204000 +SharedLibrary unknown <2ec8fd7253da4eb28abd89dffa73f81d-1> f:\ddSetup\SD\0\setup\msis\x86ret\enu\netfx_ProjectNamd64\TestILC\ExternalFiles\SharedAssemblyPath\ret\Native\SharedLibrary.pdb 0x00007ffeaa530000 - 0x00007ffeabf32000 +CryptoCoins.UWP unknown <4878a6885b4b47219f0a74aae47f7148-1> D:\data\PkgProc\JJ68QT6q2km5BO3OIyxL0w\ExtractedBundle\CryptoCoins.UWP_1.0.62.0_x64\CryptoCoins.UWP.pdb

snrnats commented 7 years ago

It appeared to be an usual app launch not a background task activation. Sorry for misleading.

achocron commented 7 years ago

Looks like we should handle this case and print a warning log. Unfortunately, we probably won't be able to collect screen size here, which is fine if there truly isn't a screen. Out of curiosity, is your application for devices that might not have screens, or does this just seem like an edge case?

Thanks for reporting the issue!

snrnats commented 7 years ago

The crashes (4 crashes on 2 devices) I've got seems to be from usual desktop PCs according to information from HockeyApp. Although these crashes seem to happened after a usual app launch, I used to observe this kind of Exceptions in my code. They were reproducible by accessing DisplayInformation.GetForCurrentView().LogicalDpi from an in-process background task that was started while the app wasn't running. That is why I guessed that it was the case. https://stackoverflow.com/questions/40700247/displayinformation-in-uwp-background-task

achocron commented 7 years ago

Yeah I've definitely seen that, and in the SDK we try to only access DisplayInformation.GetForCurrentView() on the proper thread at the right time, but clearly we are missing something. Are you able to reproduce the issue locally? It seems that no matter where I start Mobile Center, an exception does not get thrown.

snrnats commented 7 years ago

No, I can't reproduce it while it is wrapped up as in SDK. DisplayInformation.GetForCurrentView() won't be executed because there is no suitable thread while in background task. It does not seem to be an issue we are looking.

In the crash stack trace there is a line Windows.Graphics.Display.DisplayInformation.add_ColorProfileChanged. Don't sure why it's even there because SDK uses only DisplayInformation properties in the handler. Perhaps it Native Symbolicator issue or the properties also can throw exceptions or I am missing something.

Some more information: according to logs the crashes happend in 3-5 sec after App.OnLaunched(). 3 different devices so far.