diff --git a/src/Uno.UI/Controls/NSFontHelper.macOS.cs b/src/Uno.UI/Controls/NSFontHelper.macOS.cs index 15a2976e1f5bcc043e15dbd53bf274b836bc17e3..4d57fefbdb23722148732ad0d1bea7c4ea32468b 100644 --- a/src/Uno.UI/Controls/NSFontHelper.macOS.cs +++ b/src/Uno.UI/Controls/NSFontHelper.macOS.cs @@ -83,7 +83,16 @@ namespace Windows.UI private static NSFont GetDefaultFont(nfloat size, FontWeight fontWeight, FontStyle fontStyle) { - return ApplyStyle(NSFont.SystemFontOfSize(size, fontWeight.ToNSFontWeight()), size, fontStyle); + var font = NSFont.SystemFontOfSize(size, fontWeight.ToNSFontWeight()); + + if (font is not null) + { + return ApplyStyle(font, size, fontStyle); + } + else + { + throw new InvalidOperationException($"Unable to find {font}"); + } } #region Load Custom Font @@ -256,7 +265,19 @@ namespace Windows.UI { // Use the font even if the registration failed if the error code // reports the fonts have already been registered. - return NSFont.FromFontName(font.PostScriptName, size); + if (font.PostScriptName is not null) + { + return NSFont.FromFontName(font.PostScriptName, size); + } + else + { + if (typeof(NSFontHelper).Log().IsEnabled(LogLevel.Debug)) + { + typeof(NSFontHelper).Log().Debug($"Unable to register font from {file} ({error})"); + } + + return null; + } } else {