Repository: microsoft/PowerToys
File: src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/PackageWrapper.cs (C#)

Code before:

    public PackageWrapper(string name, string fullName, string familyName, bool isFramework, bool isDevelopmentMode, string installedLocation)
    {
        Name = name;
        FullName = fullName;
        FamilyName = familyName;
        IsFramework = isFramework;
        IsDevelopmentMode = isDevelopmentMode;
        InstalledLocation = installedLocation;
    }

    private static readonly Lazy<bool> IsPackageDotInstallationPathAvailable = new(() =>
        ApiInformation.IsPropertyPresent(typeof(Package).FullName, nameof(Package.InstalledLocation.Path)));

    public static PackageWrapper GetWrapperFromPackage(Package package)
    {
        ArgumentNullException.ThrowIfNull(package);

        string path;
        try
        {
            path = IsPackageDotInstallationPathAvailable.Value ? GetInstalledPath(package) : package.InstalledLocation.Path;
        }
        catch (Exception e) when (e is ArgumentException || e is FileNotFoundException || e is DirectoryNotFoundException)
        {
            Logger.LogError(e.Message);
            return new PackageWrapper(
                package.Id.Name,
                package.Id.FullName,
                package.Id.FamilyName,
                package.IsFramework,
                package.IsDevelopmentMode,
                string.Empty);
        }

        return new PackageWrapper(
                package.Id.Name,
                package.Id.FullName,
                package.Id.FamilyName,
                package.IsFramework,
                package.IsDevelopmentMode,
                path);
    }

    // This is a separate method so the reference to .InstalledPath won't be loaded in API versions which do not support this API (e.g. older then Build 19041)
    private static string GetInstalledPath(Package package)
        => package.InstalledLocation.Path;
}


Review comment (suggestion):
IMO this one doesn't seem valuable:

```
[05:00:43.0507174] [Error] PackageWrapper.cs::GetWrapperFromPackage::55
    Unable to find the specified file.
```

I get at least 10 of those on startup now, but that doesn't actually tell me anything. 

Code after:

    public PackageWrapper(string name, string fullName, string familyName, bool isFramework, bool isDevelopmentMode, string installedLocation)
    {
        Name = name;
        FullName = fullName;
        FamilyName = familyName;
        IsFramework = isFramework;
        IsDevelopmentMode = isDevelopmentMode;
        InstalledLocation = installedLocation;
    }

    private static readonly Lazy<bool> IsPackageDotInstallationPathAvailable = new(() =>
        ApiInformation.IsPropertyPresent(typeof(Package).FullName, nameof(Package.InstalledLocation.Path)));

    public static PackageWrapper GetWrapperFromPackage(Package package)
    {
        ArgumentNullException.ThrowIfNull(package);

        string path;
        try
        {
            path = IsPackageDotInstallationPathAvailable.Value ? GetInstalledPath(package) : package.InstalledLocation.Path;
        }
        catch (Exception e) when (e is ArgumentException || e is FileNotFoundException || e is DirectoryNotFoundException)
        {
            return new PackageWrapper(
                package.Id.Name,
                package.Id.FullName,
                package.Id.FamilyName,
                package.IsFramework,
                package.IsDevelopmentMode,
                string.Empty);
        }

        return new PackageWrapper(
                package.Id.Name,
                package.Id.FullName,
                package.Id.FamilyName,
                package.IsFramework,
                package.IsDevelopmentMode,
                path);
    }

    // This is a separate method so the reference to .InstalledPath won't be loaded in API versions which do not support this API (e.g. older then Build 19041)
    private static string GetInstalledPath(Package package)
        => package.InstalledLocation.Path;
}