In my UWP app, I have been retrieving the installed fonts using
try
{
var fonts = CanvasTextFormat.GetSystemFontFamilies();
return (fonts.Length>0) ? fonts.OrderBy(f => f).ToList() : new List<string>();
}
catch (Exception)
{
return new List<string>();
}
Worked fine, until it did no longer. Now, I am getting the exception
{System.IO.FileNotFoundException: The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at System.StubHelpers.StubHelpers.GetWinRTFactoryObject(IntPtr pCPCMD)
at Microsoft.Graphics.Canvas.Text.CanvasTextFormat.GetSystemFontFamilies()
at FontHelper.<>c.<LoadInstalledFonts>b__11_0()}
I have moved this section into the UI Dispatcher, thinking that maybe there were restrictions in when and by whome GetSystemFontFamilies()
can get called. That did not prevent the exception.
What is most galling: it worked before. No changes, now it just stopped working... Win2D is part of the project in version 1.25.0.
Any idea what might be causing this?
UWP: Retrieving installed fonts causes exception
I can't reproduce your issue, But I have other way to get the system font info with SharpDx.Direct2D1 nuget package.
public void GetFontLibrary()
{
SharpDX.DirectWrite.Factory factory = new SharpDX.DirectWrite.Factory();
var fontCollection = factory.GetSystemFontCollection(false);
var familCount = fontCollection.FontFamilyCount;
for (int i = 0; i < familCount; i++)
{
var fontFamily = fontCollection.GetFontFamily(i);
var familyNames = fontFamily.FamilyNames;
int index;
if (!familyNames.FindLocaleName(CultureInfo.CurrentCulture.Name, out index))
{
if (!familyNames.FindLocaleName("en-us", out index))
{
index = 0;
}
}
string name = familyNames.GetString(index);
FontList.Add(name);
}
}
User contributions licensed under CC BY-SA 3.0