Skip to content

StorageFile.Local.OpenStreamAsync always use File.Open instead of the FileAccessMode argument #21311

Closed

Description

@baskren

Current behavior 🐛

FileNotFoundException thrown when trying to write new StorageFile in a Skia.Desktop Mac app.

Image

Expected behavior 🎯

No exception thrown with correct entitlements or choice of output folder

How to reproduce it (as minimally and precisely as possible) 🔬

Demo project: https://github.com/baskren/MacDesktop_StorageFile_Write

Relevant configurations:

entitlements.plist [CLICK HERE TO EXPAND]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
	<dict>
		<key>com.apple.security.cs.allow-jit</key>
		<true/>
		<key>com.apple.security.files.user-selected.read-write</key>
		<true/>
		<key>com.apple.security.files.downloads</key>
		<true/>
		<key>com.apple.security.files.documents</key>
		<true/>
	</dict>
</plist>
  • Tried adding either/or/both of the following to the project's .csproj, in the <Properties> group:
<CodesignEntitlements Condition=" $(TargetFramework.Contains('desktop')) " >Platforms/Desktop/MacOS/entitlements.plist</CodesignEntitlements>
<UnoMacOSEntitlements Condition=" $(TargetFramework.Contains('desktop')) " >Platforms/Desktop/MacOS/entitlements.plist</UnoMacOSEntitlements>

Workaround 🛠️

None known at this time

Renderer 🎨

  • Skia
  • Native

Affected platforms 📱💻🖥️

Desktop (macOS)

Uno.Sdk version (and other relevant versions) 📦

Uno.Sdk: 6.1.23

UnoFeatures:

  • CSharpMarkup;
  • Lottie;
  • Hosting;
  • Toolkit;
  • Configuration;
  • Localization;
  • ThemeService;
  • SkiaRenderer;

IDE version 🧑‍💻

Click to expand [Mac Dev Environment]

JetBrains Rider

JetBrains Rider 2025.2
Build #RD-252.23892.524, built on August 12, 2025
Source revision: 18364647ddbb4
Licensed to Ben Askren
Subscription is active until July 10, 2026.
Runtime version: 21.0.7+6-b1038.58 aarch64 (JCEF 122.1.9)
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Toolkit: sun.lwawt.macosx.LWCToolkit
macOS 15.6
.NET Core v8.0.11 ARM64 (Server GC)
GC: G1 Young Generation, G1 Concurrent GC, G1 Old Generation
Memory: 4096M
Cores: 12
Metal Rendering is ON
Registry:
ide.lookup.shrink=true
ide.experimental.ui=true
llm.show.ai.promotion.window.on.start=false
Non-Bundled Plugins:
org.antlr.intellij.plugin (1.24)
com.intellij.resharper.HeapAllocationsViewer (2025.1.0)
com.intellij.copyright (252.23892.464)
com.redhat.devtools.lsp4ij (0.14.2)
lermitage.intellij.iconviewer (1.31.3)
com.github.camork.fileExpander (2.5)
com.wakatime.intellij.plugin (15.0.4)
com.cppcxy.Intellij-SumnekoLua (3.15.0.46-IDEA243)
com.jetbrains.rider.android (252.23892.524)
unoplatform (1.5.19)
Karma (252.25204.0)
me.rafaelldi.aspire (1.8.8)
com.intellij.resharper.azure (4.5.3)

Anything else we need to know? 💬

No response

Activity

  1. added
    triage/untriaged
    difficulty/tbd
    on Aug 20, 2025
  2. added theissue type on Aug 20, 2025
  3. baskren commented on Aug 20, 2025

    @baskren
    ContributorAuthor

    Doh! @spouliot , thanks for catching that. It should be public now.

  4. spouliot commented on Aug 21, 2025

    @spouliot
    Contributor

    Your entitlements.plist above does not match the one inside the repo.

    However that's not the problem. Entitlements are only needed if/when the app is packaged as an app bundle (and in the case of this entitlement the app would have to be sandboxed to need this).

    For a dotnet app the file system is accessible with the same permission that the current user (launching the app) has.

    The full exception is:

       at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirError)
       at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, UnixFileMode openPermissions, Int64& fileLength, UnixFileMode& filePermissions, Boolean failForSymlink, Boolean& wasSymlink, Func`4 createOpenException)
       at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
       at System.IO.File.Open(String path, FileMode mode, FileAccess access, FileShare share)
       at Windows.Storage.StorageFile.Local.OpenStreamAsync(CancellationToken ct, FileAccessMode accessMode, StorageOpenOptions options) in C:\a\1\s\src\Uno.UWP\Storage\StorageFile.Local.cs:line 43
       at Windows.Storage.StorageFile.OpenStream(CancellationToken ct, FileAccessMode accessMode, StorageOpenOptions options) in C:\a\1\s\src\Uno.UWP\Storage\StorageFile.cs:line 89
       at System.IO.WindowsRuntimeStorageExtensions.OpenStreamForWriteAsync(IStorageFile windowsRuntimeFile) in C:\a\1\s\src\Uno.UWP\System.IO\WindowsRuntimeStorageExtensions.cs:line 35
       at Windows.Storage.FileIO.WriteTextTaskAsync(IStorageFile file, String contents, Boolean append, Boolean recognizeEncoding, CancellationToken cancellationToken, Nullable`1 encoding) in C:\a\1\s\src\Uno.UWP\Storage\FileIO.cs:line 251
       at Windows.Foundation.AsyncAction.BuildTaskAsync(Func`2 taskBuilder) in C:\a\1\s\src\Uno.Foundation\Internal\AsyncAction.cs:line 61
       at UnoApp2.MainPage.<>c.<<-ctor>b__0_0>d.MoveNext() in /Users/poupou/git/external/baskren/MacDesktop_StorageFile_Write/UnoApp2/MainPage.cs:line 29
    

    and I'm surprised to see System.IO.File.Open there, since it's a new file, but it explains why the exception happens.

    I suspect something is off with the implementation of Uno's implementation of FileIO.WriteTextTaskAsync.

  5. spouliot commented on Aug 21, 2025

    @spouliot
    Contributor

    OpenStreamAsync does the call to File.Open with FileMode.Open instead of using/mapping the FileAccessMode.

    			public override Task<Stream> OpenStreamAsync(CancellationToken ct, FileAccessMode accessMode, StorageOpenOptions options)
    				=> Task.FromResult<Stream>(File.Open(Path, FileMode.Open, ToFileAccess(accessMode), ToFileShare(options)));
  6. changed the title [-][Skia.Desktop Mac] Cannot write new StorageFile?[/-] [+]`StorageFile.Local.OpenStreamAsync` always use `File.Open` instead of the `FileAccessMode` argument[/+] on Aug 21, 2025
  7. added
    area/storage 📦
    and removed
    triage/untriaged
    difficulty/tbd
    on Oct 22, 2025
  8. github-actions commented on May 15, 2026

    @github-actions
    Contributor

    This issue has had no activity for 120 days. It will be closed in 10 days if there is no further activity. Remove the Stale label or leave a comment to keep it open.

  9. added
    stale
    on May 15, 2026
  10. removed
    stale
    on May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/storage 📦

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions