From 9bf088da711d4beb5a194cb636a3bdee7ba2676c Mon Sep 17 00:00:00 2001 From: Bret Johnson Date: Mon, 7 Feb 2022 00:12:43 -0500 Subject: Protect against CurrentAppearance NRE Fix AB#1468252 Apparently there are scenarios where CurrentAppearance is not set by the client on HostResourceProvider (UITools sets it but vsmac doesn't currently) nor is NSAppearance.CurrentAppearance set on the current thread (perhaps the thread is newly created and AppKit didn't get a chance to set it), causing bug 1468252. To protect against that, we check if both are null and in that case just assume it's light theme rather than generate an NRE. --- Xamarin.PropertyEditing.Mac/HostResourceProvider.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Xamarin.PropertyEditing.Mac/HostResourceProvider.cs b/Xamarin.PropertyEditing.Mac/HostResourceProvider.cs index 4d42f06..dd2b224 100644 --- a/Xamarin.PropertyEditing.Mac/HostResourceProvider.cs +++ b/Xamarin.PropertyEditing.Mac/HostResourceProvider.cs @@ -39,7 +39,8 @@ namespace Xamarin.PropertyEditing.Mac public virtual NSImage GetNamedImage (string name) { - if ((CurrentAppearance ?? NSAppearance.CurrentAppearance).Name.ToLower ().Contains ("dark")) { + NSAppearance currentAppearance = CurrentAppearance ?? NSAppearance.CurrentAppearance; + if (currentAppearance != null && currentAppearance.Name.ToLower ().Contains ("dark")) { bool sel = name.EndsWith ("~sel"); if (sel) name = name.Substring (0, name.Length - 4); -- cgit v1.2.3