Lucas Wallner
Lucas Wallner

Reputation: 1

Authorisation error reading json file in MAUI C# net8 mac

I am working on a .NET 8 MAUI project. At some point I need to retrieve a JSON file for internationalization. But it's not working even though the file is in the correct location.

The error I get is that I don't have permission to access this file. I added permissions to my Info.plist file, but nothing has changed. I'm actually working on visual studio code because visual studio closed recently. It's not about just only json file, I try to open or read other file and it doesn't work.

It's what I add to my file :

    <key>NSFileAccessUsageDescription</key>
    <string>L'application a besoin d'accéder à tous les fichiers et dossiers de votre ordinateur pour fonctionner correctement et gérer vos fichiers personnels.</string>

    <!-- Autres autorisations d'accès spécifiques aux dossiers -->
    <key>NSDocumentsFolderUsageDescription</key>
    <string>L'application a besoin d'accéder au dossier Documents pour stocker et lire vos fichiers.</string>
    <key>NSDesktopFolderUsageDescription</key>
    <string>L'application a besoin d'accéder au dossier Bureau pour gérer les fichiers que vous y avez placés.</string>
    <key>NSDownloadsFolderUsageDescription</key>
    <string>L'application a besoin d'accéder au dossier Téléchargements pour gérer et lire les fichiers que vous avez téléchargés.</string>

using (StreamReader reader = new StreamReader(filePath, Encoding.UTF8)) { jsonContent = await reader.ReadToEndAsync(); }

Upvotes: 0

Views: 107

Answers (1)

Jack Valmadre
Jack Valmadre

Reputation: 928

One simple solution during development is to disable the app sandbox. Open the Platforms/MacCatalyst/Entitlements.plist file and set the property below to false:

        <key>com.apple.security.app-sandbox</key>
        <false/>

See also: https://tonyedwardspz.co.uk/blog/maui-access-subfolders-from-mac-desktop/

Upvotes: 0

Related Questions