Skip to content

Writing to package AppData results in broken permissions #2788

@yoshiask

Description

@yoshiask

Describe the bug

Attempting to write to the packaged app data directory using System.IO or StorageFile from a packaged WinUI 3 Desktop app causes unusual permissions issues. Any files or directories created will have the Archive | Encrypted attributes, despite being neither an archive nor encrypted. Programmatically copying the files into a different, non-AppData directory of course doesn't solve the issue (the file is still "encrypted").

Steps to reproduce the bug

  1. Clone https://github.com/yoshiask/Repros
  2. Observe the code in https://github.com/yoshiask/Repros/blob/47570dee79bd80c853be778da66eb36eae726caf/WinAppSdk/WinAppSdk/MainWindow.xaml.cs
  3. Run the WinAppSdk (Package) project and look at the debug console output.

or

  1. Create a new packaged WinUI 3 project
  2. Use ApplicationData.Current.LocalFolder.Path to get the packaged app data directory
  3. Use File.WriteAllText or StorageFile.CreateFileAsync to write to a file in that directory
  4. Observe that the file attributes are Archive | Encrypted

Expected behavior

Successfully read and write to the packaged app data directory.

Screenshots

No response

NuGet package version

1.1.3, 1.1.2

Packaging type

Packaged (MSIX)

Windows version

Windows 11 version 21H2 (22000), Windows 10 version 21H2 (19044, November 2021 Update), Windows 10 version 21H1 (19043, May 2021 Update)

IDE

Visual Studio 2022-preview, Visual Studio 2022

Additional context

This issue effectively means apps can't write to app data at all. File system virtualization for the app data directory is enabled by default for packaged apps, which means even trying to write to %appdata% directly gets redirected to the packaged app data directory. The only workaround I could find (apart from just not writing to App Data) is to disable virtualization, but App Installer refuses to install any package that declares the unvirtualizedResources rescap.

As a side note, my app also declares the packageQuery and packageManagement rescaps. Why does App Installer care that my app can write to the real App Data, but not that it can install any arbitrary package to the user's system? Seems pretty arbitrary to me, but that's a separate problem.

Metadata

Metadata

Labels

area-ApplicationDataTopics related to ApplicationData APIs in the Microsoft.Windows.Storage namespace

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions