From 459ec7ba4abe4ace0cd322dc1faf92f9fc3ba9d6 Mon Sep 17 00:00:00 2001 From: James Montemagno Date: Wed, 29 May 2019 17:51:36 -0700 Subject: [PATCH] Check for null MainView --- Xamarin.Essentials/MainThread/MainThread.uwp.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Xamarin.Essentials/MainThread/MainThread.uwp.cs b/Xamarin.Essentials/MainThread/MainThread.uwp.cs index 30170b8ea..2030eacc6 100644 --- a/Xamarin.Essentials/MainThread/MainThread.uwp.cs +++ b/Xamarin.Essentials/MainThread/MainThread.uwp.cs @@ -13,7 +13,7 @@ static bool PlatformIsMainThread // if there is no main window, then this is either a service // or the UI is not yet constructed, so the main thread is the // current thread - if (CoreApplication.MainView.CoreWindow == null) + if (CoreApplication.MainView?.CoreWindow == null) return true; return CoreApplication.MainView.CoreWindow.Dispatcher?.HasThreadAccess ?? false; @@ -22,7 +22,7 @@ static bool PlatformIsMainThread static void PlatformBeginInvokeOnMainThread(Action action) { - var dispatcher = CoreApplication.MainView.CoreWindow?.Dispatcher; + var dispatcher = CoreApplication.MainView?.CoreWindow?.Dispatcher; if (dispatcher == null) throw new InvalidOperationException("Unable to find main thread.");