microsoft / WindowsAppSDK

The Windows App SDK empowers all Windows desktop apps with modern Windows UI, APIs, and platform features, including back-compat support, shipped via NuGet.
https://docs.microsoft.com/windows/apps/windows-app-sdk/
MIT License
3.85k stars 323 forks source link

Windows.Storage.StorageLibrary.RequestAddFolderAsync() throws COMException #4590

Closed hjc4869 closed 3 months ago

hjc4869 commented 4 months ago

Describe the bug

This could be reproduced easily with a simple API call below. Similarly, StorageLibrary.RequestRemoveFolderAsync() does not work either.

It's probably caused by the underlying folder picker requiring an initialization with WinRT.Interop.InitializeWithWindow() call, but Windows.Storage.StorageLibrary API does not expose the folder picker to the API caller.

Steps to reproduce the bug

var libraryFolders = await StorageLibrary.GetLibraryAsync(KnownLibraryId.Music);
var folder = await libraryFolders.RequestAddFolderAsync();

Expected behavior

A folder picker shows up

Screenshots

No response

NuGet package version

Windows App SDK 1.5.5: 1.5.240627000

Packaging type

Packaged (MSIX)

Windows version

Insider Build (xxxxx)

IDE

Visual Studio 2022

Additional context

No response

DarranRowe commented 4 months ago

Unfortunately this is documented. Issues like these are major sticking points in using packaged applications in an AppContainer. If you are not targetting an AppContainer (i.e. setting the entrypoint to windows.partialTrustApplication or you explicitly set uap10:TrustLevel to AppContainer), the shell library API is usable. If you are targetting an AppContainer, be aware that the file pickers also don't work.

JesseCol commented 3 months ago

Hi, you might try following the instructions here if you haven't already: https://github.com/microsoft/CsWinRT/blob/master/docs/interop.md#windows-sdk

Please let us know if it didn't work for you.

Thanks!