I cant find a solution for "The component cannot be found. (Exception from HRESULT: 0x88982F50)"

1

I'm having an issue when loading a BitmapImage. I'm using 2 functions to return a bitmapimage. The first function determines which image it should load and then pass off a StorageFile to the second function to read this file in from the assets folder.

There doesn't seem to be any issue with the second function as its called elsewhere within my code. The first function will work properly if I implement it as a method within the object that has the bitmap image. However there is a weird issue with images not being displayed properly within the UI.

Function 1:

public async Task<BitmapImage> setImage(StorageFile file)
{
    switch (file.ContentType)
    {
        case ".mp3":
            var mp3 = new Uri("ms-appx:///Assets/mp3.png");
            return await pullImage(await StorageFile.GetFileFromApplicationUriAsync(mp3));
        case ".wav":
            var wav = new Uri("ms-appx:///Assets/wav.png");
            return await pullImage(await StorageFile.GetFileFromApplicationUriAsync(wav));
        case ".mid":
            var mid = new Uri("ms-appx:///Assets/midi.png");
            return await pullImage(await StorageFile.GetFileFromApplicationUriAsync(mid));
        case ".midi":
            var midi = new Uri("ms-appx:///Assets/midi.png");
            return await pullImage(await StorageFile.GetFileFromApplicationUriAsync(midi));
        default:
            var def = new Uri("ms-appx:///Assets/Square150x150Logo.scale-200.png");
            return await pullImage(await StorageFile.GetFileFromApplicationUriAsync(def));
    }
}

Function 2:

private async Task<BitmapImage> pullImage(StorageFile file)
{
    using (var randomAccessStream = await file.OpenAsync(FileAccessMode.Read))
    {
        var result = new BitmapImage();
        await result.SetSourceAsync(randomAccessStream);
        return result;
    }
}

This is how I'm calling the functions

List<File> files = new List<File>();
IReadOnlyList<StorageFile> subfiles = await globalFolder.GetFilesAsync();

foreach(StorageFile subfile in subfiles){
    files.Add(new File { Name = subfile.Name, Image = await pullImage(subfile)});
}

The current code should return the bitmapImage for the defualt case as the cases for file.ContentType are currently incorrect. Insted I recieve the following error The component cannot be found. (Exception from HRESULT: 0x88982F50)

Also I am using the same method within the case statements in another function to get a bitmapimage and there is no issue at all.

c#
uwp
asked on Stack Overflow May 21, 2019 by Dspens

1 Answer

2

I cant find a solution for “The component cannot be found. (Exception from HRESULT: 0x88982F50)”

I checked your code. The problem is that you have used wrong method. You need use setImage method to create BitmapImage for your File instance, but not pullImage.

List<File> files = new List<File>();
IReadOnlyList<StorageFile> subfiles = await KnownFolders.PicturesLibrary.GetFilesAsync();
foreach (StorageFile subfile in subfiles)
{
    files.Add(new File { Name = subfile.Name, Image = await setImage(subfile)});
}

And do not miss modify the source image name for mid file.

case ".mid":
var mid = new Uri("ms-appx:///Assets/midi.png"); // wrong name
return await pullImage(await StorageFile.GetFileFromApplicationUriAsync(mid));
answered on Stack Overflow May 22, 2019 by Nico Zhu - MSFT

User contributions licensed under CC BY-SA 3.0