MAUI Resource not found on Android Only

Dan Schio 25 Reputation points
2024-02-19T06:33:31.17+00:00

I am using the M2Mqtt nuget package with a MAUI application, connecting via TLS with a certificate. When I deploy to physical devices (both an iOS and Android), the iOS works perfectly while the Android throws an error saying it cannot find the file. The certificate is a .crt placed in the Resources/Raw folder with MauiAsset as its build activity. What's the trick to including this file in the physical build?

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

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,126 Reputation points Microsoft External Staff
    2024-02-20T05:54:40.34+00:00

    Hello,

    What's the trick to including this file in the physical build?

    For MauiAssert resource files, the official recommended access method is to use the OpenAppPackageFileAsync API.

    FileSystem.OpenAppPackageFileAsync Files that were added to the project with the Build Action of MauiAsset can be opened with this method. .NET MAUI projects will process any file in the Resources\Raw folder as a MauiAsset.

    Please refer to Bundled files for more detailed information.

    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.


0 additional answers

Sort by: Most helpful

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.