awesome-inc / FontAwesome.Sharp

A library for using Font Awesome in WPF & Windows Forms applications
Apache License 2.0
384 stars 89 forks source link

Fix .NET Core 3.X/.NET 5 WinForm Icon Issues #48

Closed FoxCouncil closed 3 years ago

FoxCouncil commented 3 years ago

This should resolve these two issues: #47 #46

TL;DR: The issue stems from the order in which the new runtime in .NET Core initializes static fields.

Details: In FormsIconHelper.FontFamilyFor() the static field FormsIconHelper.Fonts is not accessed yet and thus does not load the actual packaged font data resources, causing the call to Typeface.TryGetGlyphTypeface(GlyphTypeface) to fail as the font isn't actually loaded into memory/PrivateFontCollection yet.

Commit Notes: Added a field accessor to trigger the field initialization. Get error checking for free!

FoxCouncil commented 3 years ago

@mkoertgen Just as a note, I can't merge this PR as I don't have write access to this repo. You'd have to click the button.