Error loading font 'Assets/Fonts/Segoe UI.ttf'. on log

Dani_S 4,501 Reputation points
2025-03-13T10:01:37.4166667+00:00

Hi,

I have this error when running the MAUI as exe.

I do not have this fonts on my app in RESOURCES/FONTS and not resister it.

2025-03-13 11:57:26,921 [1] ERROR Microsoft.Maui.FontManager - Error loading font 'Assets/Fonts/Segoe UI.ttf'.

System.InvalidOperationException: This operation is not supported for a relative URI.

at System.Uri.get_LocalPath()

at Microsoft.Maui.FontManager.FindFontFamilyName(String fontFile)

2025-03-13 11:57:26,940 [1] ERROR Microsoft.Maui.FontManager - Error loading font 'Assets/Fonts/Segoe UI.otf'.

Thanks,

Developer technologies | .NET | .NET MAUI
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,126 Reputation points Microsoft External Staff
    2025-03-14T05:26:38.88+00:00

    Hello,

    This is a bug specific to unpackaged distributions. You can refer to the known thread in github for a solution or wait for the development team to fix it.

    This is a workaround for apps that are experiencing this:

    #if WINDOWS
    Microsoft.Maui.Handlers.LabelHandler.Mapper.AppendToMapping("FontFamily", (handler, element) =>
    {
        if (element.Font.Family == "FontAwesome")
        {
            const string FontAwesomeFamily = "ms-appx:///Fontawesome6brands.otf#Font Awesome 6 Brands";
            handler.PlatformView.FontFamily = new Microsoft.UI.Xaml.Media.FontFamily(FontAwesomeFamily);
        }
    });
    #endif
    

    I am looking into why this is happening as the code is the same and should produce the same result packaged/unpackaged...

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.