In UWP app I'm trying to access images from app storage folder using StorageFolder.GetFilesAsync() nethod.
public async void GetMediaFiles()
{
_localMediaFolder = await GetOrCreateFolder(ApplicationData.Current.LocalFolder, "Media", ReservationId.ToString());
IReadOnlyList<StorageFile> files = await _localMediaFolder.GetFilesAsync();
}
Iv'e tried to use known folder as well with the same result.
public async void GetMediaFiles()
{
StorageFolder picturesFolder = KnownFolders.PicturesLibrary;
_tempMediaFolder = await picturesFolder.CreateFolderAsync("media", CreationCollisionOption.OpenIfExists);
IReadOnlyList<StorageFile> storageFilesOperation = await _tempMediaFolder.GetFilesAsync();
}
Instead of 'IReadOnlyList' Im getting 'System.__ComObject'. I can't cast it to 'IReadOnlyList' and don't know how to use it to get the files i need.
Iv'e tried to use known folder as well with the same result. there is no exception int the Output indicating that the app have no access to the file or folder. Iv'e also checked the app manifest for access for the pictures library.
How Can I Fix this?
This is by design. There's no need to cast
System.__ComObject
toIReadOnlyList
becauseIReadOnlyList
is an interface, which means when you create a variable of this type you can assign to it an instance of any class that implements theIReadOnlyList
interface, andSystem.__ComObject
is such class. You can continue working withstorageFilesOperation
as usual, e.g. delete all files: