When StorageFile.GetScaledImageAsThumbnailAsync could fail?

Neo 186 Reputation points

I am using StorageFile.GetScaledImageAsThumbnailAsync to get thumbnails of downloaded JPEG pictures (Bing daily's).

According to the doc, the method will return "null if there is no thumbnail image associated with the item". But for my tests, the method always returns correct thumbnails. I am wondering under what conditions would the method fail, so that I can handle the error with precaution.

Universal Windows Platform (UWP)
No comments
{count} votes

1 answer

Sort by: Most helpful
  1. 2020-11-24T12:38:55.833+00:00

    Hello, @Neo Welcome to Microsoft Q&A,

    Derive from document, this method will return null if there is no thumbnail image associated with the item. But it hard to reproduce, because, if you can view the file in the file explorer, it means the file contains thumbnail image.

    And for your requirement, we suggest add null condition to notice user there is no thumbnail for current file and use try catch block to notice user exception message when getting file's thumbnail.

        var thumbnail = await file.GetScaledImageAsThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.SingleItem);  
        if(thumbnail == null)  
            System.Diagnostics.Debug.WriteLine("----------thumbnail is null--------");  
    catch (Exception ex)  

    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.