Answered by:
COMException (E_FAIL) accessing library content from WinRT apps

Question
-
I get a COM exception (E_FAIL) when I run this WinRT-based C# code under my Windows user account:
TextBlock.Text = KnownFolders.PicturesLibrary.DisplayName; // this line runs OK
IReadOnlyList<StorageFile> fileList = await KnownFolders.PicturesLibrary.GetFilesAsync();
// the above throws COMException: Error HRESULT E_FAIL has been returned from a call to a COM component.TextBlock.Text += " - " + fileList.Count.ToString();
The same exception is caught when using DocumentsLibrary, MusicLibrary, or VideosLibrary instead of PicturesLibraries.
If I open Windows 8's default apps (Photos, Music), they list correctly all SkyDrive and Facebook pictures, but NOT the local pictures and music from the Pictures and Music libraries; the apps don't crash but indicate that the "Pictures Library" and "Music Library" are "empty" (listing 0 pictures, 0 songs)! I suspect they receive the same exception internally.
If I open Windows Explorer in Desktop mode and navigate to the Libraries, they all list content correctly. (I have previously rebuilt the indexes, just to make sure the index was not the issue, and have reset all libraries to their defaults, so all libraries are currently loading files only from C:\Users\[username] and C:\Users\Public, i.e. My Pictures, My Music, etc., and Public Pictures, Public Music, etc.)
All pictures and music are stored on the local C: drive, represented by a standard hard disk (not mounted from any external storage device) and are correctly displayed in Desktop mode on all programs (Windows Media Center, Windows Media Player and Windows Photo Gallery).
The current machine has been upgraded to Windows 8 Pro from Windows 7, but I can confirm that all library folders have full control permissions set for my user, Administrators group, and SYSTEM (inherited), and the SFC check returns no violations.
My computer is within a domain, and my user (linked to my Microsoft account on the current computer) is a local machine administrator. On a separate machine that is also in the same domain, I have no issue with library access from WinRT, even from the same domain user account (linked to the same Microsoft account), so the issue seems to be local to my Windows user account.
Does anyone know a way to correct the apparently corrupted Windows user account's library links used by WinRT? (I mean, at least what registry locations should one check trying to find the root cause of this issue?) Again, the problem seems to be deeply related to the local Windows user settings, and only for Windows Store apps (for all of them), as on Desktop mode all libraries work well in all programs.
Sorin Dolha, DlhSoft
- Moved by Jesse Jiang Friday, May 24, 2013 7:31 AM
Wednesday, May 22, 2013 1:24 PM
Answers
-
Since this affects all apps for the user it sounds like a problem with the system rather than with your code. For help on fixing that try the Windows 8 forums on http://answers.microsoft.com or in the Windows 8 IT Pro forums on TechNet.
--Rob
Wednesday, May 22, 2013 2:03 PM -
Eventually, thanks to a suggestion in a recent post from a Microsoft Answers discussion, I found a resolution for all the issues (including library reading and opening URLs on clicking links in Windows Store apps).
To resolve the problem, use Regedit and delete this key: HKEY_CURRENT_USER\Software\Classes\CLSID (make a backup first). Then sign out and in again, or reboot. Libraries can now be successfully read from Windows 8 apps!
Note that deleting the CLSID key from HKEY_CURRENT_USER will clean up the current settings for the current user profile only, and will not affect the entire machine settings.
Finally, I’ve re-added some of the keys in the backup of the CLSID, i.e. only those with keys with actual values for sub-keys. After that everything still works, and I have no fear that any real personal settings are removed.
Don't forget to repeat these steps for all affected user profiles.
Sorin Dolha, DlhSoft
- Marked as answer by Just Karl Monday, October 28, 2013 8:14 PM
Monday, October 28, 2013 8:43 AM
All replies
-
Further information: I have noticed that Kindle WinRT app (from Amazon) isn't able to download any book from the Cloud to Device when I use my Windows account (it reports "Disk full" error, even that there is no book downloaded locally and the total disk size used by the app is reported by the OS to be very small, e.g. < 10 MB).
Uninstalling and reinstalling Kindle app (as for Photos and Music apps) doesn't help.
If I sign out from Kindle and register with a different Amazon account (using the same Windows account), the correct books in the Cloud are listed, but download still doesn't work - disk full being reported (probably again as an internal COM exception from WinRT core which is assumed by Kindle app to be caused by a disk full situation).
If I use another Windows user and the same Amazon account (on the same machine), Kindle app works correctly.
Sorin Dolha, DlhSoft
Wednesday, May 22, 2013 1:50 PM -
Since this affects all apps for the user it sounds like a problem with the system rather than with your code. For help on fixing that try the Windows 8 forums on http://answers.microsoft.com or in the Windows 8 IT Pro forums on TechNet.
--Rob
Wednesday, May 22, 2013 2:03 PM -
OK, thanks. I've re-posted the question on Answers community, and later also to TechNet community. The interested people should follow these links:
Answers: http://answers.microsoft.com/en-us/windows/forum/windows_8-pictures/comexception-efail-accessing-library-content-from/484cb9fb-7ff3-4ba5-9bdd-90fa50e42f78 - redirected question to TechNet:
Sorin Dolha, DlhSoft
- Edited by Sorin Dolha Friday, May 24, 2013 8:18 AM Added more info
Wednesday, May 22, 2013 2:22 PM -
Eventually, thanks to a suggestion in a recent post from a Microsoft Answers discussion, I found a resolution for all the issues (including library reading and opening URLs on clicking links in Windows Store apps).
To resolve the problem, use Regedit and delete this key: HKEY_CURRENT_USER\Software\Classes\CLSID (make a backup first). Then sign out and in again, or reboot. Libraries can now be successfully read from Windows 8 apps!
Note that deleting the CLSID key from HKEY_CURRENT_USER will clean up the current settings for the current user profile only, and will not affect the entire machine settings.
Finally, I’ve re-added some of the keys in the backup of the CLSID, i.e. only those with keys with actual values for sub-keys. After that everything still works, and I have no fear that any real personal settings are removed.
Don't forget to repeat these steps for all affected user profiles.
Sorin Dolha, DlhSoft
- Marked as answer by Just Karl Monday, October 28, 2013 8:14 PM
Monday, October 28, 2013 8:43 AM