Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows FontImageSourceService assumes MSIX packaging #15802

Closed
jeremy-visionaid opened this issue Jun 23, 2023 · 31 comments · Fixed by #20790 or #21144
Closed

Windows FontImageSourceService assumes MSIX packaging #15802

jeremy-visionaid opened this issue Jun 23, 2023 · 31 comments · Fixed by #20790 or #21144
Labels
area-fonts Custom fonts and Font related API's blocked Work that is currently blocked fixed-in-8.0.10 fixed-in-9.0.0-preview.2.10293 p/1 Work that is important, and has been scheduled for release in this or an upcoming sprint partner/winui WinUI / Project Reunion platform/windows 🪟 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@jeremy-visionaid
Copy link
Contributor

jeremy-visionaid commented Jun 23, 2023

Description

The Windows FontRegistrar assumes the application is packaged with MSIX (all paths are prefixed with "ms-appx:///"), so font loading fails if/when MSIX packaging is disabled.

https://github.com/dotnet/maui/blob/main/src/Core/src/Fonts/FontRegistrar.Windows.cs#L11

13:05:02:928	Microsoft.Maui.FontManager: Error: Error loading font 'ms-appx:///OpenSans-Regular.ttf'.

Switching to AddEmbeddedResourceFont also fails unless using MSIX packaging.

Steps to Reproduce

  1. Create a new MAUI App
  2. Disable MSIX Packaging in csproj:
		<!-- Disable MSIX -->
		<WindowsPackageType>None</WindowsPackageType>
		<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
		<Platforms>x64</Platforms>
		<Platform>x64</Platform>
		<RuntimeIdentifiers>win10-x64</RuntimeIdentifiers>
		<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
		<WindowsAppSdkDeploymentManagerInitialize>false</WindowsAppSdkDeploymentManagerInitialize>

Run the app and see error like:

13:05:02:928	Microsoft.Maui.FontManager: Error: Error loading font 'ms-appx:///OpenSans-Regular.ttf'.

Link to public reproduction project repository

https://github.com/molesmoke/MauiFontImageSourceTest

Version with bug

7.0.86

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

10.0.19041.0

Did you find any workaround?

Could implement a custom registrar service, but haven't tried

Relevant log output

13:05:02:928	Microsoft.Maui.FontManager: Error: Error loading font 'ms-appx:///OpenSans-Regular.ttf'.

Microsoft.Maui.FontImageSourceService: Warning: Unable to generate font image ''.

System.ArgumentException: Value does not fall within the expected range.
   at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|20_0(Int32 hr)
   at WinRT.ExceptionHelpers.ThrowExceptionForHR(Int32 hr)
   at Microsoft.Graphics.Canvas.Text.CanvasTextLayout._ICanvasTextLayoutFactory.Create(ICanvasResourceCreator resourceCreator, String textString, CanvasTextFormat textFormat, Single requestedWidth, Single requestedHeight)
   at Microsoft.Graphics.Canvas.Text.CanvasTextLayout.<>c__DisplayClass11_0.<.ctor>b__0()
   at Microsoft.Graphics.Canvas.Text.CanvasTextLayout..ctor(ICanvasResourceCreator resourceCreator, String textString, CanvasTextFormat textFormat, Single requestedWidth, Single requestedHeight)
   at Microsoft.Maui.FontImageSourceService.RenderImageSource(IFontImageSource imageSource, Single scale)
   at Microsoft.Maui.FontImageSourceService.GetImageSourceAsync(IFontImageSource imageSource, Single scale, CancellationToken cancellationToken)

VS bug #1923183

@jeremy-visionaid jeremy-visionaid added the t/bug Something isn't working label Jun 23, 2023
@drasticactions
Copy link
Contributor

I assume this would go in line with #10564, @mattleibow?

@jeremy-visionaid
Copy link
Contributor Author

jeremy-visionaid commented Jun 23, 2023

@drasticactions Thanks for pointing that out. This one might also be related to #9104

@jsuarezruiz jsuarezruiz added platform/windows 🪟 area-fonts Custom fonts and Font related API's labels Jun 23, 2023
@jeremy-visionaid
Copy link
Contributor Author

Now I understand what's going on a bit more, I believe this is actually a dupe of #9104. i.e. The ms-appx URI is intentional and the failure was also due to an issue in WinUI3/Win2D. Nonetheless, I still observe the issue on a local build of MAUI release/7.0.2xxsr7 even though all the PRs have been merged there. @mattleibow perhaps this should be closed in favour of reopening #9104?

@jeremy-visionaid
Copy link
Contributor Author

jeremy-visionaid commented Jun 23, 2023

I spoke to soon. The FontManager does manage to load the fonts OK, which is what #9104 is about, but FontImageSource is still broken, which my repro project was also testing. So, even though the initial error is resolved on release/7.0.2xxsr7, #9104 is not sufficient to resolve all the problems constructing CanvasTextLayouts:

Microsoft.Maui.FontImageSourceService: Warning: Unable to generate font image ''.

System.ArgumentException: Value does not fall within the expected range.
   at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|20_0(Int32 hr)
   at WinRT.ExceptionHelpers.ThrowExceptionForHR(Int32 hr)
   at Microsoft.Graphics.Canvas.Text.CanvasTextLayout._ICanvasTextLayoutFactory.Create(ICanvasResourceCreator resourceCreator, String textString, CanvasTextFormat textFormat, Single requestedWidth, Single requestedHeight)
   at Microsoft.Graphics.Canvas.Text.CanvasTextLayout.<>c__DisplayClass11_0.<.ctor>b__0()
   at Microsoft.Graphics.Canvas.Text.CanvasTextLayout..ctor(ICanvasResourceCreator resourceCreator, String textString, CanvasTextFormat textFormat, Single requestedWidth, Single requestedHeight)
   at Microsoft.Maui.FontImageSourceService.RenderImageSource(IFontImageSource imageSource, Single scale)
   at Microsoft.Maui.FontImageSourceService.GetImageSourceAsync(IFontImageSource imageSource, Single scale, CancellationToken cancellationToken)

@jeremy-visionaid jeremy-visionaid changed the title Windows FontRegistrar assumes MSIX packaging Windows FontImageSourceService assumes MSIX packaging Jun 25, 2023
@jsuarezruiz jsuarezruiz added this to the Backlog milestone Jun 26, 2023
@ghost
Copy link

ghost commented Jun 26, 2023

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

@XamlTest XamlTest added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Jul 26, 2023
@XamlTest
Copy link

Verified this on Visual Studio Enterprise 17.7.0 Preview 5.0. Repro on Windows 11 .NET 8.0 with below Project:
MauiFontImageSourceTest.zip

@mattleibow
Copy link
Member

I had a look and I can't get the FontImageSource implementation to load fonts by file or in unpackaged apps (which load by file). The exception says:

The URI specified in the CanvasTextFormat's FontFamily has an invalid scheme; the scheme may be omitted, or must be one of ms-appx:// or ms-appdata://.

I will open a bug in Win2D

@mattleibow
Copy link
Member

Opened this one and will follow up with that team: microsoft/Win2D#941

@mattleibow mattleibow added partner/winui WinUI / Project Reunion blocked Work that is currently blocked labels Nov 29, 2023
@mobynet1
Copy link

mobynet1 commented Dec 8, 2023

I have been seeing this error for months. I am also doing an unpackaged deployment, but I am not seeing the same exact error that @jeremy-visionaid reported... but, very similar.

I have been seeing (formatting done by NLog):

2023-12-08 09:30:15.2885 ERROR 
  Call site:         FontManager.FindFontFamilyName
  Method name:       Microsoft.Maui.FontManager.FindFontFamilyName
  Line:              0
  Exception Type:    System.ArgumentException
  Exception Message: The parameter is incorrect.

Assets/Fonts/Segoe UI.ttf is not a valid absolute URI.
  Stack Trace:       at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|39_0(Int32 hr)
   at ABI.System.WinRTUriRuntimeClassFactory.CreateUri(String uri)
   at ABI.System.Uri.CreateMarshaler(Uri value)
   at Microsoft.Graphics.Canvas.Text.CanvasFontSet._ICanvasFontSetFactory.Create(Uri uri)
   at Microsoft.Graphics.Canvas.Text.CanvasFontSet.<>c__DisplayClass11_0.<.ctor>b__0()
   at Microsoft.Graphics.Canvas.Text.CanvasFontSet..ctor(Uri uri)
   at Microsoft.Maui.FontManager.FindFontFamilyName(String fontFile)
  Additional Info:   Error loading font 'Assets/Fonts/Segoe UI.ttf'.

I am not loading this particular font, nor is it listed anywhere in my solution. Here is the section where I load fonts:

			.ConfigureFonts (fonts => {
				_ = fonts.AddFont ("FontAwesome6Brands-Regular-400.otf", "FaBrands");
				_ = fonts.AddFont ("FontAwesome6Duotone-Solid-900.otf", "FaDuotone");
				_ = fonts.AddFont ("FontAwesome6Pro-Light-300.otf", "FaLight");
				_ = fonts.AddFont ("FontAwesome6Pro-Regular-400.otf", "FaRegular");
				_ = fonts.AddFont ("FontAwesome6Pro-Solid-900.otf", "FaSolid");
				_ = fonts.AddFont ("FontAwesome6Pro-Thin-100.otf", "FaThin");
				_ = fonts.AddFont ("OpenSans-Regular.ttf", "OpenSansRegular");
				_ = fonts.AddFont ("OpenSans-Semibold.ttf", "OpenSansSemibold");
				_ = fonts.AddFont ("Poppins-Black.otf", "PoppinsBlack");
				_ = fonts.AddFont ("Poppins-BlackItalic.otf", "PoppinsBlackItalic");
				_ = fonts.AddFont ("Poppins-Bold.otf", "PoppinsBold");
				_ = fonts.AddFont ("Poppins-BoldItalic.otf", "PoppinsBoldItalic");
				_ = fonts.AddFont ("Poppins-ExtraBold.otf", "PoppinsExtraBold");
				_ = fonts.AddFont ("Poppins-ExtraBoldItalic.otf", "PoppinsExtraBoldItalic");
				_ = fonts.AddFont ("Poppins-ExtraLight.otf", "PoppinsExtraLight");
				_ = fonts.AddFont ("Poppins-ExtraLightItalic.otf", "PoppinsExtraLightItalic");
				_ = fonts.AddFont ("Poppins-Italic.otf", "PoppinsItalic");
				_ = fonts.AddFont ("Poppins-Light.otf", "PoppinsLight");
				_ = fonts.AddFont ("Poppins-LightItalic.otf", "PoppinsLightItalic");
				_ = fonts.AddFont ("Poppins-Medium.otf", "PoppinsMedium");
				_ = fonts.AddFont ("Poppins-MediumItalic.otf", "PoppinsMediumItalic");
				_ = fonts.AddFont ("Poppins-Regular.otf", "PoppinsRegular");
				_ = fonts.AddFont ("Poppins-SemiBold.otf", "PoppinsSemiBold");
				_ = fonts.AddFont ("Poppins-SemiBoldItalic.otf", "PoppinsSemiBoldItalic");
				_ = fonts.AddFont ("Poppins-Thin.otf", "PoppinsThin");
				_ = fonts.AddFont ("Poppins-ThinItalic.otf", "PoppinsThinItalic");
				_ = fonts.AddFont ("Segoe-Ui-Bold.ttf", "SegoeUiBold");
				_ = fonts.AddFont ("Segoe-Ui-Regular.ttf", "SegoeUiRegular");
				_ = fonts.AddFont ("Segoe-Ui-Semibold.ttf", "SegoeUiSemibold");
				_ = fonts.AddFont ("Segoe-Ui-Semilight.ttf", "SegoeUiSemilight");
			})

All of these fonts are included in my Resources\Fonts folder, so I am confused as to where the 'Assets/Fonts/Segoe UI.ttf' is coming from. In my .csproj file there is this for fonts:

		<!-- Custom Fonts -->
		<MauiFont Include="Resources\Fonts\*" />

but that is a standard project file entry.

I remember during a preview release that the splash screen was defined like '.../Assets/...' and there were instructions in the release notes on how to get around that issue. The code that is throwing this error is located in Microsoft.Maui.FontManager inside the FindFontFamilyName method. There is a constant for TypicalFontAssetsPath which is defined as Assets/Fonts/ and an array, TypicalFontFileExtensions, which has .ttf and '.otf' as elements that correlate to the exceptions in my log file (the other is exactly as the one shown, but it is looking for the .otf version. In the FindFontFamilyName method there is an if statement that seems to only look for the actual path if the app has been deployed as a packaged app, which mine is not....

				// unpackaged apps can't load files using packaged schemes
				if (!AppInfoUtils.IsPackagedApp)
				{
					var path = fontUri.AbsolutePath.TrimStart('/');
					if (FileSystemUtils.TryGetAppPackageFileUri(path, out var uri))
						fontUri = new Uri(uri, UriKind.RelativeOrAbsolute);
				}

If this is truly the case, the call to TryGetAppPackageFileUri is perhaps being passed an incorrect initial path. My fonts are getting loaded, so something is happening that should not be for font look-ups for unpackaged apps.

As a rule, I do not like errors in the error log that I have no control over. If there is a way to stop this error, I'd love to know!!

@jingliancui
Copy link

met same issue, my product heavy depend on fontawesome.

@AathifMahir
Copy link

Facing the same issue here as well AathifMahir/MauiIcons#79

@samhouts samhouts added the p/1 Work that is important, and has been scheduled for release in this or an upcoming sprint label Dec 19, 2023
@GuidoNeele
Copy link
Contributor

Is there perhaps a workaround for this issue?

@jeremy-visionaid
Copy link
Contributor Author

@GuidoNeele I had to use SVG based icons instead

@BurkusCat
Copy link
Contributor

Opened this one and will follow up with that team: microsoft/Win2D#941

It doesn't look like there is a huge amount of activity on that repository (and there are bugs affecting WinUI open from 2017). Is there anything that can be done to prioritise that issue?

I wouldn't normally ask this but I see this issue is marked as a "p/1" and it feels like it might be a few .NET versions away from being resolved.

@jeremy-visionaid
Copy link
Contributor Author

@BurkusCat I'm not sure how much you can tell about what's going on via GitHub. Seems like most of the work for WinUI & Win2D take part behind closed doors. You can see the work for a similar issue was tracked via a different system: microsoft/Win2D#891

I was watching WinUI 3 for a year waiting for the release blockers to be fixed before I could target an app against it, and one day with no warning around v1.4 the issues were closed and it was finally "good enough". Though both WinUI and MAUI are improving, they're still pretty niggly.

@jeremy-visionaid
Copy link
Contributor Author

Maybe @Redth could give this issue a poke, since he likely knows the folk involved in the related fix?

@mattleibow
Copy link
Member

Reopening this just until the new Win2D is released and updated. But, SR3 will be ready for it!

@AndreasReitberger
Copy link

Thank you so much for your help on that 🙂

@BurkusCat
Copy link
Contributor

Hey @mattleibow , I thought I'd give the changes a try early. Should the below changes work?

  1. I've updated to the latest .NET MAUI version:
    <MauiVersion>8.0.10</MauiVersion>

  2. Updated Win2D for Windows builds

  <!-- Windows specifics-->
  <ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">
    <PackageReference Include="Microsoft.Graphics.Win2D" Version="1.2.0" />
  </ItemGroup>
Before above changes: After above changes:
image image

With CLR exceptions turned on, I get this error:

System.ArgumentException: 'The parameter is incorrect.

The URI specified in the CanvasTextFormat's FontFamily has an invalid scheme; the scheme may be omitted, or must be one of ms-appx:// or ms-appdata://.'

@AndreasReitberger
Copy link

Facing the same issue as @BurkusCat
I updated to 8.0.10 and set WinUI to 1.2.0.

Fonts still are missing and icons are shown as [ ]

image

@mattleibow any chance for a feedback from you? Should this already work or do we need to wait for SR4?
Thank you :)

@hardikphd
Copy link

We are also facing same issue with 8.0.10 and WinUI 1.2.0.

@AndreasReitberger
Copy link

I opened a new issue here: #21333

@jeremy-visionaid
Copy link
Contributor Author

Just to note here as well as on #21333, that this works OK for me with MAUI 8.0.14 and WinUI 1.2.0.

@pouchbunny
Copy link

I was having a problem all of a sudden today even though my app was working just fine, but then the font doesn't fall within the expected etc. One of the fonts was mistyped as .ttv not .ttf, but then it did it for another font and I'm like wtf, the OpenSans ones were just fine but the only difference between this other font and the three others I have was that there were spaces. I removed them and the exception went away DESPITE, again, working until after I updated to the most recent build 8.0.1 and continued seeing it after upgrading to 9.0.0.

@jingliancui
Copy link

I was having a problem all of a sudden today even though my app was working just fine, but then the font doesn't fall within the expected etc. One of the fonts was mistyped as .ttv not .ttf, but then it did it for another font and I'm like wtf, the OpenSans ones were just fine but the only difference between this other font and the three others I have was that there were spaces. I removed them and the exception went away DESPITE, again, working until after I updated to the most recent build 8.0.1 and continued seeing it after upgrading to 9.0.0.

I think you would better to raise a new issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-fonts Custom fonts and Font related API's blocked Work that is currently blocked fixed-in-8.0.10 fixed-in-9.0.0-preview.2.10293 p/1 Work that is important, and has been scheduled for release in this or an upcoming sprint partner/winui WinUI / Project Reunion platform/windows 🪟 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.