Open ctmobiledev opened 2 years ago
@ctmobiledev Judging by the fact that this is failing inside of Platform specific code (In this, run in Android) I don't think MAUI is influencing this and it's just an Android issue with the platform (Although I could be missing something here). @jonathanpeppers Do you have any ideas?
@drasticactions it is failing inside the BCL:
> System.IO.IOException: Operation not permitted
--- End of inner exception stack trace ---
at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirectory, Func`2 errorRewriter)
at Interop.CheckIo(Error error, String path, Boolean isDirectory, Func`2 errorRewriter)
at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode)
at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
at System.IO.Strategies.UnixFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
Which means the OS gave an error code that indicates the file wasn't writeable.
If you tried to write to this same file in a Java/Kotlin Android app it would probably fail the same way? @ctmobiledev can you test that?
In either case, I don't see anything to be fixed in MAUI for this. If there is a bug, it looks like some change is needed in dotnet/runtime.
Ahhhh, but the same code when run under Xamarin.Forms completes without issue. The code was, in fact, developed originally using Xamarin.Forms, and I ported it over to .NET MAUI, hence my reason for suspicion.
I could create a completely new "dummy" Xamarin.Forms project with the ScopedStorage et al modules for comparison, but I've used this code in other applications without problems.
Get Outlook for Androidhttps://aka.ms/AAb9ysg
From: Tim Miller @.> Sent: Tuesday, March 15, 2022 7:17:37 PM To: dotnet/maui @.> Cc: CTMobileDev @.>; Mention @.> Subject: Re: [dotnet/maui] Scoped Storage (Android) Not Allowing Files To Be Saved, But Saves To Internal Storage Work Fine (Issue #5295)
@ctmobiledevhttps://github.com/ctmobiledev Judging by the fact that this is failing inside of Platform specific code (In this, run in Android) I don't think MAUI is influencing this and it's just an Android issue with the platform (Although I could be missing something here). @jonathanpeppershttps://github.com/jonathanpeppers Do you have any ideas?
— Reply to this email directly, view it on GitHubhttps://github.com/dotnet/maui/issues/5295#issuecomment-1068593315, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AGN4XN6C27NJNPOXJ2T6RUDVAESCDANCNFSM5QXUGSHQ. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you were mentioned.Message ID: @.***>
@steveisok would someone on the Mono team be able to check if there is a new problem here in .NET 6?
@mkhamoyan Please take a look.
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.
Description
NOTE: This issue occurs with Visual Studio Version 17.2.0 Preview 1.0. There's no item for that in the drop-down below, so I wanted to report that first.
This is an issue I've only observed writing an app using .NET MAUI for the Android platform, and it pertains solely to a feature unique to Android: ScopedStorage.
Simply put, an app can create a folder successfully using the Android folder picker, but when processing attempts to create a new file in that selected folder - such as with WriteAllLines - processing chokes with a System.UnauthorizedAccessException.
I tested by attempting a write to the Android app's internal "sandbox" space, which normally has a folder named similar to this:
/storage/emulated/0/Android/data/com.companyname.mauiinputoutputtest1/files
The exception above doesn't happen, and the file is visible when an Android device is attached to a workstation via USB and the File Manager.
Here's the project I used (with bin and obj folders removed to reduce space):
maui-io-scoped-storage-create-file-bug.zip
The file in question is Platforms/Android/FileHelper.cs.
The routines of interest are:
public static int BackupAllData()
- starting at line 126public static Boolean CreateBackupFolder(String bfolder)
- starting at line 217public static void MakeFile(String fileName)
- starting at line 329To see the exception occur, comment out line 346:
346 var outputFile = Path.Combine(PrivateExternalFolder, outname);
And comment in line 350:
350 var outputFile = Path.Combine(deviceStoragePath, fileName);
If your test results are consistent with mine, your output should resemble the following:I can get along with internal storage for the time being, but it would be nice to have scoped storage working, since that's a big deal with Android 11 now. Users wanting to create new files where they choose needs to work.
Thanks for your help!
Steps to Reproduce
Version with bug
Unknown/Other (please specify)
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
Android 11
Did you find any workaround?
For the time being, I just use internal storage rather than user-selected scoped storage.
Relevant log output