Accessing KnownFolders.PicturesLibrary throws "System.Exception: Unspecified error"

Simon Knuth 1 Reputation point
2021-04-03T20:23:59.39+00:00

Hi there,

I've got an interesting issue that's pretty hard to reproduce.

What my code aims to do
My app interacts with scanners to receive image files, which are then saved to a folder. By default, this folder is inside the Pictures Library. The app manifest states that access to the Pictures Library is required. At first launch a folder called "Scans" is created in the Pictures Library.

What's happening
Creating/getting the folder in the Pictures Library fails. It is likely that the folder even already exists on many devices. The exception is:

  • "System.Exception: Unspecified error (Exception from HRESULT: 0x80004005)"
  • Inner Exception: "System.Exception: Unspecified error (Exception from HRESULT: 0x80004005)"

Only ~1% of users face this issue and there isn't any specific pattern. I've got machines with different builds of Windows using different languages from different manufacturers reporting this.

The code

try
{
    scanFolder = await KnownFolders.PicturesLibrary.CreateFolderAsync("Scans", CreationCollisionOption.OpenIfExists);
}
catch (UnauthorizedAccessException exc)
{
   log.Error(exc, "Creating a new scanFolder in PicturesLibrary failed. (Unauthorized)");
   return;
}
catch (Exception exc)
{
   log.Error(exc, "Creating a new scanFolder in PicturesLibrary failed.");
   return;
}

The exception occurs in line 3.

Any guess as to what is causing this issue? My ability to perform tests is pretty limited since I personally can't reproduce this. The same issue was reported here in 2018, but without any solution. It suggests that merely accessing the KnownFolders.XXX property is already triggering the exception.

Universal Windows Platform (UWP)
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.