UnauthorizedAccessException on android

2.7k views Asked by At

I have an UnauthorizedAccessException on Android when trying to retrieve some files. The odd things is that it worked for months before this evening.

The only things I did the last couple of hours are (even if I can't see how it may have changed anything):

  • uploading the apk to enable alpha testing the Google Play Services
  • adding a keystore and signing the app (tried with no signature, same problem)
  • removing last instance of my app on my test device (not compatible with the signed version)

The app is built with Unity 5.5.0f3, I use Application.persistentDataPath to build the path I'm trying to access.

here is the callstack for the exception :

UnauthorizedAccessException: Access to the path "/storage/emulated/0/Android/data/com.<mycompany>.<myproductname>/files/Saves" is denied.
at System.IO.Directory.GetFileSystemEntries (System.String path, System.String searchPattern, FileAttributes mask, FileAttributes attrs) [0x00000] in <filename unknown>:0
at System.IO.Directory.GetFiles (System.String path, System.String searchPattern) [0x00000] in <filename unknown>:0
at System.IO.Directory.GetFiles (System.String path, System.String searchPattern, SearchOption searchOption) [0x00000] in <filename unknown>:0
at ProfileManager.ParseDirForProfiles (.DirName _dir, .FileExtension _ext) [0x00000] in <filename unknown>:0
at SaveManager.ParseDirForProfiles () [0x00000] in <filename unknown>:0
at myproductname.OnStart () [0x00000] in <filename unknown>:0
at StateMachine.Start () [0x00000] in <filename unknown>:0

CallStack

The code causing problem : Code

and the relevant settings : Settings 1 Settings 2

1

There are 1 answers

1
j__m On BEST ANSWER

The directory may still be owned by the previous, incompatible version of the app. Delete the directory and let your app recreate it the next time you run it.

This kind of problem will never occur if your app is updated normally.