wpfbackground-taskdesktop-bridgeappxmanifestout-of-process

WPF Desktop Bridge out-of-process background task cannot access Documents folder


I'm developing a WPF (Desktop Bridge) application that performs some logic on startup and in out-of-process background task. This logic creates and uses a file in the user's Documents folder.

I've created out-of-process BG task in WPF (Desktop Bridge) application according to the article on Microsoft Developer Blog: Link

To use the Documents folder, I've added the appropriate permission to the manifest of Package project:

<Capabilities>
    <uap:Capability Name="documentsLibrary" />
</Capabilities>

Also, I've added File Type Associations permission on the file type I'm going to create and open in Documents folder and Background Task declaration with General/System event task type.

But, unfortunately, the call of KnownFolders.DocumentsLibrary.CreateFolderAsync("SubfolderName", CreationCollisionOption.OpenIfExists) method in BG task results in exception: Access is denied..

Stack Trace:

at Windows.Storage.KnownFolders.get_DocumentsLibrary()
at *...

The call of the same logic in the code of WPF application is successful. Adding the same permissions to the BackgroundTaskWrapper (UWP) project doesn't solve the problem.

Task is working properly only on Windows 2004. It's not working on previous versions of Windows: 1909, 1903, 1809, 1709 (not tested on older versions, due to target version of project).

Sample: Github


Solution

  • WPF Desktop Bridge out-of-process background task cannot access Documents folder

    During the testing, it could create text.bgtxt file successfully within background task in my environment (os version 2004). And the problem has fixed in latest OS version. please try to update your os to latest version.

    The main problem is that not many users have migrated to version 2004 yet (my app has many users on 1809-1909).

    I tried to make the folder in the picture library after add picture library capability, and it works. So currently the work around is use picture library to replace documents library.