can not read assets file in ios in maui?

mc 6,236 Reputation points
2025-11-10T15:28:44.8033333+00:00

there is AboutAssetx.txt and font1.ttf with same code i can read AboutAssets.txt but can not read font1.ttf and all set to MauiAsset and were in Raw folder why?

in android I can read it.

I use FileSystem.OpenAppPackageFileAsync

Developer technologies | .NET | .NET MAUI
{count} votes

Answer accepted by question author
  1. Jack Dang (WICLOUD CORPORATION) 3,965 Reputation points Microsoft External Staff Moderator
    2025-11-14T02:41:09.81+00:00

    Hi @mc ,

    Sorry to bother you - and I’m really glad to hear you managed to identify the cause of the issue!

    Just to add some technical background for anyone else who may hit the same behavior:

    According to Microsoft’s official documentation for file-system helpers, any file added with the MauiAsset build action can normally be opened using FileSystem.OpenAppPackageFileAsync, and .NET MAUI processes all files under Resources/Raw as MauiAsset:

    https://learn.microsoft.com/dotnet/maui/platform-integration/storage/file-system-helpers?view=net-maui-10.0

    However, Microsoft also documents that font files (such as .ttf and .otf) are intended to be placed under Resources/Fonts and use the MauiFont build action instead of MauiAsset:

    https://learn.microsoft.com/dotnet/maui/user-interface/fonts?view=net-maui-10.0

    Because of that difference, when a TrueType font is included as a MauiAsset on iOS, the system may not allow it to be treated as a raw data stream at runtime. This explains why your .txt file worked correctly, but the .ttf file did not - and why renaming the font (for example, from font1.ttffont1.db) allows iOS to treat it like a normal asset rather than a font resource.

    This means the behavior you observed is consistent with how iOS and MAUI handle fonts vs. generic assets, even though Microsoft does not explicitly document a limitation about opening .ttf files with OpenAppPackageFileAsync on iOS. Your rename solution is therefore a valid workaround when you need to read the raw bytes of a font file instead of registering it as a UI font.

    Thanks again for sharing your findings - this will definitely help others who attempt to read font files as raw assets on iOS using FileSystem.OpenAppPackageFileAsync.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Q&A Assist
    2025-11-10T15:29:08.9466667+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    In .NET MAUI, when you are trying to read assets like fonts or text files, it is important to ensure that the files are correctly set up in the project. Since you mentioned that you can read AboutAssets.txt but not font1.ttf, here are a few things to check:

    1. File Location: Ensure that both files are indeed in the Resources\Raw folder and that their properties are set to MauiAsset.
    2. File Access: The method FileSystem.OpenAppPackageFileAsync should work for both text files and font files if they are properly configured. If you can read the text file but not the font, it might be an issue with how the font file is being accessed or used in your application.
    3. Font Registration: Make sure that the font is registered correctly in your MAUI project. This typically involves adding the font to your MauiProgram.cs file or ensuring it's referenced in your XAML if you're using it in UI components.
    4. Platform Differences: There might be platform-specific differences in how files are accessed. While you can read the font file on Android, ensure that your iOS project is set up correctly to handle font files as well.

    If you have verified all of the above and still face issues, consider checking the output logs for any errors during the file access process, which might provide more insight into what is going wrong.


    References:

    0 comments No comments

Your answer

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