Repository: microsoft/PowerToys
File: src/modules/peek/Peek.FilePreviewer/Previewers/ImagePreviewer/Helpers/PropertyHelper.cs (C#)

Code before:

    public static class PropertyHelper
    {
        public static Task<Size> GetImageSize(string filePath)
        {
            return Task.Run(() =>
            {
                try
                {
                    var propertyStore = PropertyStoreShellApi.GetPropertyStoreFromPath(filePath, PropertyStoreShellApi.PropertyStoreFlags.OPENSLOWITEM);
                    if (propertyStore != null)
                    {
                        var width = (int)PropertyStoreShellApi.GetUIntFromPropertyStore(propertyStore, PropertyStoreShellApi.PropertyKey.ImageHorizontalSize);
                        var height = (int)PropertyStoreShellApi.GetUIntFromPropertyStore(propertyStore, PropertyStoreShellApi.PropertyKey.ImageVerticalSize);

                        Marshal.ReleaseComObject(propertyStore);
                        return new Size(width, height);
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }

                return Size.Empty;
            });
        }

        public static Task<ulong> GetFileSizeInBytes(string filePath)
        {
            ulong bytes = 0;
            try
            {
                var propertyStore = PropertyStoreShellApi.GetPropertyStoreFromPath(filePath, PropertyStoreShellApi.PropertyStoreFlags.OPENSLOWITEM);
                if (propertyStore != null)
                {
                    bytes = PropertyStoreShellApi.GetULongFromPropertyStore(propertyStore, PropertyStoreShellApi.PropertyKey.FileSizeBytes);

                    Marshal.ReleaseComObject(propertyStore);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            return Task.FromResult(bytes);
        }

        public static Task<string> GetFileType(string filePath)
        {

Review comment (bug):
For several file types including HEIC (but also CRW, ERF, FFF, X3F etc)  that have no thumbnails, the crash was actually when attempting to get ImageSize. We currently try 2 ways of getting image size, but both throw an exception. In the future, might want to look into yet another way of getting ImageSize for those file types, and catch exceptions along the way so we can try all 3 methods. (I do see file dimensions in File Explorer->Properties->ExtraProperties, so there must be an API that can get it...)

Code after:
using Windows.Win32.UI.Shell.PropertiesSystem;

namespace Peek.FilePreviewer.Previewers
{
    public static class PropertyHelper
    {
        public static Task<Size> GetImageSize(string filePath)
        {
            return Task.Run(() =>
            {
                try
                {
                    var propertyStore = PropertyStoreHelper.GetPropertyStoreFromPath(filePath, GETPROPERTYSTOREFLAGS.GPS_OPENSLOWITEM);
                    if (propertyStore != null)
                    {
                        var width = (int)propertyStore.GetUInt(PropertyKey.ImageHorizontalSize);
                        var height = (int)propertyStore.GetUInt(PropertyKey.ImageVerticalSize);

                        Marshal.ReleaseComObject(propertyStore);
                        return new Size(width, height);
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }

                return Size.Empty;
            });
        }

        public static Task<ulong> GetFileSizeInBytes(string filePath)
        {
            ulong bytes = 0;
            try
            {
                var propertyStore = PropertyStoreHelper.GetPropertyStoreFromPath(filePath, GETPROPERTYSTOREFLAGS.GPS_OPENSLOWITEM);
                if (propertyStore != null)
                {
                    bytes = propertyStore.GetULong(PropertyKey.FileSizeBytes);

                    Marshal.ReleaseComObject(propertyStore);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            return Task.FromResult(bytes);
        }