Open janne-hmp opened 1 month ago
Hi I'm an AI powered bot that finds similar issues based off the issue title.
Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!
MauiFont
not usable if added in MauiLibrary
(#21771), similarity score: 0.71Note: You can give me feedback by thumbs upping or thumbs downing this comment.
The problem seems to be that Assets/Fonts/Lato.ttf
is not an absolute URI, not so much that the file does not exist.
@janne-hmp are you not seeing this issue on net8?
@janne-hmp are you not seeing this issue on net8?
Not sure, as our app is built using .NET 9. SkiaSharp did not work properly in .NET 8 MAUI (at least for our app). .NET 9 in turn worked well.
I can repro this issue at Windows platform on the latest main 17.12.0 Preview 2.0 (MAUI Version: 9.0.0-preview.6.24327.7 & 9.0.0-preview.5.24307.10).
I am also getting this issue, but I am on net8 with MAUI 8.0.80. Same code runs fine on macOS.
System.ArgumentException: The parameter is incorrect.
Assets/Fonts/ProximaNovaSemiBold.otf is not a valid absolute URI.
at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|39_0(Int32 hr)
at WinRT.ExceptionHelpers.ThrowExceptionForHR(Int32 hr)
at ABI.System.WinRTUriRuntimeClassFactory.CreateUriForMarshaling(String uri)
at ABI.System.Uri.CreateMarshaler2(Uri value)
at Microsoft.Graphics.Canvas.Text.CanvasFontSet._ICanvasFontSetFactory.Create(Uri uri)
at Microsoft.Graphics.Canvas.Text.CanvasFontSet..ctor(Uri uri)
at Microsoft.Maui.FontManager.FindFontFamilyName(String fontFile)
EDIT 1: Oh.. something is weird here. I am not using ProximaNovaSemiBold.otf
.
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
fonts.AddFont("proxima_nova_bold.ttf", "ProximaNovaBold");
fonts.AddFont("proxima_nova_regular.ttf", "ProximaNovaRegular");
fonts.AddFont("proxima_nova_semibold.ttf", "ProximaNovaSemibold");
})
EDIT 2:
Well, my problem is "fixed". Apparelty I was naming the font ProximaNovaRegular
in MauiProgram.cs
, but I was using it as ProximaNova-Regular
in styles. I couldn't see the correct combination of what these should be. So I just changed everything to this format,
fonts.AddFont("proxima_nova_regular.ttf", "proxima_nova_regular");
and it seems to go away. Looks like something is not finding the font and falling back to disk.
EDIT 3: Just to confirm I updated my style to look like this,
<Style TargetType="Label">
<Setter Property="FontFamily" Value="test_font" />
</Style>
and then when I run my app I see these errors.
Microsoft.Maui.FontManager: Error: Error loading font 'Assets/Fonts/test_font.ttf'.
System.ArgumentException: The parameter is incorrect.
Assets/Fonts/test_font.ttf is not a valid absolute URI.
at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|39_0(Int32 hr)
at WinRT.ExceptionHelpers.ThrowExceptionForHR(Int32 hr)
at ABI.System.WinRTUriRuntimeClassFactory.CreateUriForMarshaling(String uri)
at ABI.System.Uri.CreateMarshaler2(Uri value)
at Microsoft.Graphics.Canvas.Text.CanvasFontSet._ICanvasFontSetFactory.Create(Uri uri)
at Microsoft.Graphics.Canvas.Text.CanvasFontSet..ctor(Uri uri)
at Microsoft.Maui.FontManager.FindFontFamilyName(String fontFile)
Exception thrown: 'System.ArgumentException' in WinRT.Runtime.dll
WinRT information: Assets/Fonts/test_font.otf is not a valid absolute URI.
Microsoft.Maui.FontManager: Error: Error loading font 'Assets/Fonts/test_font.otf'.
System.ArgumentException: The parameter is incorrect.
Assets/Fonts/test_font.otf is not a valid absolute URI.
at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|39_0(Int32 hr)
at WinRT.ExceptionHelpers.ThrowExceptionForHR(Int32 hr)
at ABI.System.WinRTUriRuntimeClassFactory.CreateUriForMarshaling(String uri)
at ABI.System.Uri.CreateMarshaler2(Uri value)
at Microsoft.Graphics.Canvas.Text.CanvasFontSet._ICanvasFontSetFactory.Create(Uri uri)
at Microsoft.Graphics.Canvas.Text.CanvasFontSet..ctor(Uri uri)
at Microsoft.Maui.FontManager.FindFontFamilyName(String fontFile)
Description
We see in Windows app the following handled exception:
System.ArgumentException
: The parameter is incorrect.Assets/Fonts/Lato.ttf
is not a valid absolute URI. It is thrown byWinRTUriRuntimeClassFactory.CreateUriForMarshaling(string uri)
, and logged byMicrosoft.Maui.FontManager
. I do not have a Fonts directory under Assets (but rather under Resources).It happens in
AppShell.Navigated
that has been called byAppShell.Appearing
.That font seems to be some sort of a default font. I tried adding it to
Resources\Fonts
, but it did not seem to help with the exception.Steps to Reproduce
Link to public reproduction project repository
https://github.com/hyvanmielenpelit/GnollHack
Version with bug
9.0.0-preview.6.24327.7
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
Windows
Affected platform versions
Windows 11
Did you find any workaround?
The exception is handled, so this only seems to produce unnecessary logging. It might cause some problems elsewhere potentially.
Relevant log output