C
C#•4mo ago
Emmanuel

.NET Maui font problems

Hi, I am building an app in .Net Maui. I use custom fonts. They worked very well and suddenly, the program started to crash, saying the fonts uri was not correct. I haven't moved anything. I opened a similar project and it worked well, same configuration. I simply do lot get it.
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
fonts.AddFont("BLOOMINGS.OTF", "Bloomings");
fonts.AddFont("FUTURA BOOK FONT.TTF", "FuturaBook");
fonts.AddFont("FUTURA BOOK ITALIC FONT.TTF", "FuturaBookItalic");
});

#if DEBUG
builder.Logging.AddDebug();
#endif
return builder.Build();
}
}
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
fonts.AddFont("BLOOMINGS.OTF", "Bloomings");
fonts.AddFont("FUTURA BOOK FONT.TTF", "FuturaBook");
fonts.AddFont("FUTURA BOOK ITALIC FONT.TTF", "FuturaBookItalic");
});

#if DEBUG
builder.Logging.AddDebug();
#endif
return builder.Build();
}
}
<Entry
Grid.Column="2"
x:Name="Search"
Placeholder="Search"
PlaceholderColor="#BFBFBF"
BackgroundColor="#FFFFFF"
FontSize="11"
FontFamily="FUTURA BOOK FONT"
TextColor="#383838"
VerticalTextAlignment="Start"
HorizontalTextAlignment="End"
HorizontalOptions="Fill"

VerticalOptions="Center"
WidthRequest="90"
/>
<Entry
Grid.Column="2"
x:Name="Search"
Placeholder="Search"
PlaceholderColor="#BFBFBF"
BackgroundColor="#FFFFFF"
FontSize="11"
FontFamily="FUTURA BOOK FONT"
TextColor="#383838"
VerticalTextAlignment="Start"
HorizontalTextAlignment="End"
HorizontalOptions="Fill"

VerticalOptions="Center"
WidthRequest="90"
/>
71 Replies
Buddy
Buddy•4mo ago
$details
MODiX
MODiX•4mo ago
When you ask a question, make sure you include as much detail as possible. Such as code, the issue you are facing, and what you expect the result to be. Upload code here https://paste.mod.gg/ (see $code for more information on how to paste your code)
Emmanuel
Emmanuel•4mo ago
And the error:
System.ArgumentException: The parameter is incorrect.

Assets/Fonts/FUTURA BOOK 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.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)
'ChlorophyGUITests.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\PrivateAssemblies\Runtime\Microsoft.VisualStudio.Debugger.Runtime.NetCoreApp.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ChlorophyGUITests.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.2\netstandard.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
System.ArgumentException: The parameter is incorrect.

Assets/Fonts/FUTURA BOOK 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.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)
'ChlorophyGUITests.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\PrivateAssemblies\Runtime\Microsoft.VisualStudio.Debugger.Runtime.NetCoreApp.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ChlorophyGUITests.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.2\netstandard.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
leowest
leowest•4mo ago
FontFamily="FUTURA BOOK FONT"
leowest
leowest•4mo ago
No description
leowest
leowest•4mo ago
u named it FuturaBookItalic when u add it so you should call FontFamily="FuturaBookItalic" if you still have issues I would try to rename the otf file to lower case and remove the space to see if it finds it first
Emmanuel
Emmanuel•4mo ago
I use FUTURA BOOK. I tried renaming too. Matched perfectly, without success, with or without spaces.
leowest
leowest•4mo ago
and have u tried to name the otf file all lower case with no space? in your solution explorer I've seen Maui having issue with files with name spaces and upper case letter some times
leowest
leowest•4mo ago
No description
leowest
leowest•4mo ago
No description
leowest
leowest•4mo ago
u can also open the otf/ttf file and use the name inside because it can sometimes contain multiple types so here I can use FontFamily="Eina03-Bold"
Emmanuel
Emmanuel•4mo ago
Pretty sure I did, will try again and get back to you! Thanks!
Emmanuel
Emmanuel•4mo ago
No description
Emmanuel
Emmanuel•4mo ago
csproj
No description
Emmanuel
Emmanuel•4mo ago
No description
Emmanuel
Emmanuel•4mo ago
No description
Emmanuel
Emmanuel•4mo ago
Somehow it gets stuck on this capital letter thing Even though it's nowhere
leowest
leowest•4mo ago
u have to remove the other 2 with space on the name from here I mean, otherwise it will still try to load the wrong named fonts and fail wait why they marked as none remove ah no that's right mine is the same thou it should be something else
Emmanuel
Emmanuel•4mo ago
Yeah, they are genuinely nowhere and not referenced either
leowest
leowest•4mo ago
in the properties its marked as MauiFont right?
Emmanuel
Emmanuel•4mo ago
yep
leowest
leowest•4mo ago
No description
leowest
leowest•4mo ago
I mean in here you still have the 2 entries of the files with space on the name u need to remove those
Emmanuel
Emmanuel•4mo ago
My problem was fixed, but it crashes anyway
No description
Emmanuel
Emmanuel•4mo ago
I do not get the error caused by the fonts though
leowest
leowest•4mo ago
try to clean the solution then rebuild
Emmanuel
Emmanuel•4mo ago
The rebuild succeeded but it crashes when i Debug
leowest
leowest•4mo ago
in xaml how are u calling the font inthe fontfamily
Emmanuel
Emmanuel•4mo ago
No description
Emmanuel
Emmanuel•4mo ago
as I should as far as i know
leowest
leowest•4mo ago
and does it work if u remove it?
Emmanuel
Emmanuel•4mo ago
nope
leowest
leowest•4mo ago
and if u comment the 2 entries loading the fonts in the maui cs file does it work?
Emmanuel
Emmanuel•4mo ago
fonts.AddFont("bloomings.otf", "bloomings"); fonts.AddFont("futurabook.ttf", "futurabook"); fonts.AddFont("futurabookitalic.ttf", "futurabookitalic"); These? crashes too This is insane It worked all afternoon
leowest
leowest•4mo ago
then your problem now is else where I guess do u have a github of this project?
Emmanuel
Emmanuel•4mo ago
GitHub
GitHub - dotnetemmanuel/ChlorophyGUITests
Contribute to dotnetemmanuel/ChlorophyGUITests development by creating an account on GitHub.
leowest
leowest•4mo ago
is it up to date with the issue ur having?
Emmanuel
Emmanuel•4mo ago
yeah I just pushed it
leowest
leowest•4mo ago
ok give me 15 minutes and I will take a look
Emmanuel
Emmanuel•4mo ago
Awesome! Thanks!
leowest
leowest•4mo ago
you're building it for windows?
Emmanuel
Emmanuel•4mo ago
right now yeah it's a university project
leowest
leowest•4mo ago
ok found it
<Image Source="succulents.jpg"
VerticalOptions="FillAndExpand"
Aspect="AspectFill"
Opacity="0.8"
Margin="-230,0,0,0"/>
<Image Source="succulents.jpg"
VerticalOptions="FillAndExpand"
Aspect="AspectFill"
Opacity="0.8"
Margin="-230,0,0,0"/>
Emmanuel
Emmanuel•4mo ago
Seriously?
leowest
leowest•4mo ago
that was causing it to crash
Emmanuel
Emmanuel•4mo ago
Why?
leowest
leowest•4mo ago
the negative 230 is probably causing some issue I dont know what the image is or what u want to do with it so hard to tell
Emmanuel
Emmanuel•4mo ago
Haha, i just want to offset it It should fill the whole border, bit I want to offset it To the left
leowest
leowest•4mo ago
I have also removed one of the fonts they were both the same file wise apparently
Emmanuel
Emmanuel•4mo ago
Which one?
leowest
leowest•4mo ago
futura I left this one fonts.AddFont("futurabook.ttf", "futurabook");
leowest
leowest•4mo ago
No description
Emmanuel
Emmanuel•4mo ago
Haha yeah that image shouldnt look that way Will try tomorrow Thanks so much! Will get back to you. Whats your timezone?
leowest
leowest•4mo ago
im not sure I understood that tip of something at the bottom in the middle?
Emmanuel
Emmanuel•4mo ago
Yeah, you should see a whole fucking loads of succulents Will keep trying tomorrow
leowest
leowest•4mo ago
ok but you want to fill it inside not on the border? -3
leowest
leowest•4mo ago
No description
leowest
leowest•4mo ago
you should probably add a grid to your border and work from there u will get a much easier result then negativating margins
Emmanuel
Emmanuel•4mo ago
True Thanks for the advice Started with maui yesterday so it's still a bit fresh
leowest
leowest•4mo ago
its ok 😉 althou I would suggest you either use WPF or UWP if your target is only windows due to the proportion of that image u will have a hard time filling it the way u want I see what is going on its rescaling it making it grow under
Emmanuel
Emmanuel•4mo ago
Yeah, our teacher chose Maui, this app will be for android and windows. Thats why
leowest
leowest•4mo ago
fair, at least you're learning xaml and not winforms 🙂
Emmanuel
Emmanuel•4mo ago
Maui is quite buggy But i like it somehow
leowest
leowest•4mo ago
well youre dealing with edge technology so yeah there will be things that wont be as simple as u think they will 🙂 and u might need to do hacks to get around some
Emmanuel
Emmanuel•4mo ago
It's not as counterintuitive as i thought
leowest
leowest•4mo ago
but MAUI is getting a lot of love so who knows in a few more years its just sad it gets no linux support which would probably make it a lot more popular
Emmanuel
Emmanuel•4mo ago
People are too dismissive too fast imo
leowest
leowest•4mo ago
I wouldn't say dismissive its just that they need to consider for example say u need a crossplatform app that also works on linux MAUI does all the 4 other platform u need so now u need to create a MAUI app and then another app with another tech to cover for linux so you have to maintain 2 separated code bases as oppose to choose a tech that covers all of it so people just go for the latter either it being electron, tauri, avalonia or w/e Also as far as I remember, last I checked MAUI was still not production ready even thou it does work quite well to some extent
Emmanuel
Emmanuel•4mo ago
Yeah, i meant people in general, complaining about Maui not woeking properly. It's still quite impressive
leowest
leowest•4mo ago
yeah, I mean that will always exist specially when its something free and some parts get more attention than others.
Emmanuel
Emmanuel•4mo ago
Thanks again for your help! I got it to work in no time! Really appreciate
Want results from more Discord servers?
Add your server
More Posts