Reputation: 1
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>
I have all autorisation on my pc for the project
The problem is from the project not outside
Entitlements.plist is correct
I had autorisation on my json file
error : System.UnauthorizedAccessException: Access to the path '/Users/user/Projects/ProjetSAE/equipe1b/Resources/Localization/fr.json' is denied.
json path : /Users/user/Projects/ProjetSAE/equipe1b/Resources/Localization/fr.json
extract of the code :
using (StreamReader reader = new StreamReader(filePath, Encoding.UTF8)) { jsonContent = await reader.ReadToEndAsync(); }
Path to open the file :
string currentDirectory = Directory.GetCurrentDirectory(); filePath = Path.Combine(currentDirectory, "Resources", "Localization", $"{languageCode}.json");
When I try to use it on Windows it works but not on Mac
Upvotes: 0
Views: 107
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