androidxamarin.androidunauthorizedaccessexcepti

Suddenly System.UnauthorizedAcessException on one device


I am debugging my Xamarin.Android App alternately with 2 devices

On my MainLauncher-Activity the user is directly asked for the Permission (Camera, RecordAudio, ReadExternalStorage, WriteExternalStorage, etc.)

After the permission-check the App writes a new entry to the logfile. Everything just works fine on all devices until now (10th September 2019)

On my Huawei Honor I get a System.UnauthorizedAccessException: 'Access to path is denied.'

enter image description here

I haven no idea how to approach this error.

Only Android 9 still works!


yesterday, all devices worked fine


EDIT: I could fix this problem with the workaround mentioned in this Thread https://github.com/xamarin/xamarin-android/issues/3426

Using

var fileBytes = File.ReadAllBytes(tempfile);
File.WriteAllBytes(filePath, fileBytes);

instead of

File.Copy(tempfile, filePath, true);

Solution

  • Using

    var fileBytes = File.ReadAllBytes(tempfile);
    File.WriteAllBytes(filePath, fileBytes);
    

    instead of

    File.Copy(tempfile, filePath, true);
    

    is a workaround for this issue. You can find an open discussion here

    https://github.com/xamarin/xamarin-android/issues/3426