This repository was archived by the owner on May 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 497
This repository was archived by the owner on May 15, 2024. It is now read-only.
[Bug] Android FilePicker FileResult.OpenReadAsync throws UnauthorizedAccessException #1584
Copy link
Copy link
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Description
After a file is selected with file picker, OpenReadAsync
throws UnauthorizedAccessException
when trying to open the file.
The same code base is working with 1.6.0-pre4.
When FileResult.FullPath
observed, it returns /storage/emulated/0/testfile.txt
, while 1.6.0-pre4 returns content://com.android.externalstorage.documents/document/primary%3Atestfile.txt
.
Stack trace:
12-11 10:57:13.338 E/mono (25387): Unhandled Exception:
12-11 10:57:13.338 E/mono (25387): System.UnauthorizedAccessException: Access to the path "/storage/emulated/0/testfile.txt" is denied.
12-11 10:57:13.338 E/mono (25387): at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) [0x001aa] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/corlib/System.IO/FileStream.cs:239
12-11 10:57:13.338 E/mono (25387): at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/corlib/System.IO/FileStream.cs:91
12-11 10:57:13.338 E/mono (25387): at (wrapper remoting-invoke-with-check) System.IO.FileStream..ctor(string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare)
12-11 10:57:13.338 E/mono (25387): at System.IO.File.OpenRead (System.String path) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.IO.FileSystem/src/System/IO/File.cs:266
12-11 10:57:13.338 E/mono (25387): at Xamarin.Essentials.FileBase.PlatformOpenReadAsync () [0x00000] in D:\a\1\s\Xamarin.Essentials\FileSystem\FileSystem.android.cs:368
12-11 10:57:13.338 E/mono (25387): at Xamarin.Essentials.FileBase.OpenReadAsync () [0x00000] in D:\a\1\s\Xamarin.Essentials\FileSystem\FileSystem.shared.cs:172
12-11 10:57:13.338 E/mono (25387): at XamarinEssentialsFilePickerTest.MainPage.ReadFileAsync () [0x000f5] in C:\VS\XamarinEssentialsFilePickerTest\XamarinEssentialsFilePickerTest\XamarinEssentialsFilePickerTest\MainPage.xaml.cs:34
12-11 10:57:13.338 E/mono (25387): at XamarinEssentialsFilePickerTest.MainPage.Button_OnClicked (System.Object sender, System.EventArgs e) [0x00020] in C:\VS\XamarinEssentialsFilePickerTest\XamarinEssentialsFilePickerTest\XamarinEssentialsFilePickerTest\MainPage.xaml.cs:44
12-11 10:57:13.338 E/mono (25387): at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.1(intptr,intptr)
12-11 10:57:13.338 E/mono (25387): at (wrapper native-to-managed) Android.Runtime.DynamicMethodNameCounter.1(intptr,intptr)
12-11 10:57:13.338 E/mono-rt (25387): [ERROR] FATAL UNHANDLED EXCEPTION: System.UnauthorizedAccessException: Access to the path "/storage/emulated/0/testfile.txt" is denied.
12-11 10:57:13.338 E/mono-rt (25387): at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) [0x001aa] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/corlib/System.IO/FileStream.cs:239
12-11 10:57:13.338 E/mono-rt (25387): at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/corlib/System.IO/FileStream.cs:91
12-11 10:57:13.338 E/mono-rt (25387): at (wrapper remoting-invoke-with-check) System.IO.FileStream..ctor(string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare)
12-11 10:57:13.338 E/mono-rt (25387): at System.IO.File.OpenRead (System.String path) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.IO.FileSystem/src/System/IO/File.cs:266
12-11 10:57:13.338 E/mono-rt (25387): at Xamarin.Essentials.FileBase.PlatformOpenReadAsync () [0x00000] in D:\a\1\s\Xamarin.Essentials\FileSystem\FileSystem.android.cs:368
12-11 10:57:13.338 E/mono-rt (25387): at Xamarin.Essentials.FileBase.OpenReadAsync () [0x00000] in D:\a\1\s\Xamarin.Essentials\FileSystem\FileSystem.shared.cs:172
12-11 10:57:13.338 E/mono-rt (25387): at XamarinEssentialsFilePickerTest.MainPage.ReadFileAsync () [0x000f5] in C:\VS\XamarinEssentialsFilePickerTest\XamarinEssentialsFilePickerTest\XamarinEssentialsFilePickerTest\MainPage.xaml.cs:34
12-11 10:57:13.338 E/mono-rt (25387): at XamarinEssentialsFilePickerTest.MainPage.Button_OnClicked (System.Object sender, System.EventArgs e) [0x00020] in C:\VS\XamarinEssentialsFilePickerTest\XamarinEssentialsFilePickerTest\XamarinEssentialsFilePickerTest\MainPage.xaml.cs:44
12-11 10:57:13.338 E/mono-rt (25387): at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.1(intptr,intptr)
12-11 10:57:13.338 E/mono-rt (25387): at (wrapper native-to-managed) Android.Runtime.DynamicMethodNameCounter.1(intptr,intptr)
Steps to Reproduce
- Use
FilePicker.PickAsync
to select a file and get aFileResult
instance - Call
OpenReadAsync
on the returnedFileResult
instance
Expected Behavior
OpenReadAsync
returns an awaitable Task<Stream>
for the selected file.
Actual Behavior
OpenReadAsync
throws System.UnauthorizedAccessException: Access to the path "/storage/emulated/0/testfile.txt" is denied.
.
Basic Information
- Version with issue: 1.6.0-pre5
- Last known good version: 1.6.0-pre4
- Platform Target Frameworks:
- Android: 10.0 (SDK: 11.1.0.17)
- Nuget Packages:
- Xamarin.Forms: 4.8.0.1687
- Xamarin.Essentials: 1.6.0-pre5
- Affected Devices: Android (Samsung SM-G970F - API 29)
Reproduction Link
https://github.com/attilavlacsil/XamarinEssentialsFilePickerTest
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working