Repository: PowerShell/PowerShell
File: src/System.Management.Automation/engine/Utils.cs (C#)

Code before:
                return s_windowsPowerShellVersion;
            }

            string engineKeyPath = RegistryStrings.MonadRootKeyPath + "\\" +
                PSVersionInfo.RegistryVersionKey + "\\" + RegistryStrings.MonadEngineKey;

            using (RegistryKey engineKey = Registry.LocalMachine.OpenSubKey(engineKeyPath))
            {
                if (engineKey != null)
                {
                    s_windowsPowerShellVersion = engineKey.GetValue(RegistryStrings.MonadEngine_MonadVersion) as string;
                    return s_windowsPowerShellVersion;
                }
            }

            return string.Empty;
        }
#endif

        internal static string DefaultPowerShellAppBase => GetApplicationBase(DefaultPowerShellShellID);

        internal static string GetApplicationBase(string shellId)
        {
            var baseDirectory = Path.GetDirectoryName(typeof(PSObject).Assembly.Location);
            if (string.IsNullOrEmpty(baseDirectory))
            {
                // need to remove any trailing directory separator characters
                baseDirectory = AppContext.BaseDirectory.TrimEnd(Path.DirectorySeparatorChar);
            }

            return baseDirectory;
        }

        private static string[] s_productFolderDirectories;

        private static string[] GetProductFolderDirectories()
        {
            if (s_productFolderDirectories == null)
            {
                List<string> baseDirectories = new List<string>();

                // Retrieve the application base from the registry
                string appBase = Utils.DefaultPowerShellAppBase;
                if (!string.IsNullOrEmpty(appBase))
                {
                    baseDirectories.Add(appBase);
                }
#if !UNIX
                // Now add the two variations of System32
                baseDirectories.Add(Environment.GetFolderPath(Environment.SpecialFolder.System));
                string systemX86 = Environment.GetFolderPath(Environment.SpecialFolder.SystemX86);

Review comment (suggestion):
```suggestion
            // Use the location of SMA.dll as the application base if it exists,
            // otherwise, use the base directory from `AppContext`.
            var baseDirectory = Path.GetDirectoryName(typeof(PSObject).Assembly.Location);
```

Code after:
                return s_windowsPowerShellVersion;
            }

            string engineKeyPath = RegistryStrings.MonadRootKeyPath + "\\" +
                PSVersionInfo.RegistryVersionKey + "\\" + RegistryStrings.MonadEngineKey;

            using (RegistryKey engineKey = Registry.LocalMachine.OpenSubKey(engineKeyPath))
            {
                if (engineKey != null)
                {
                    s_windowsPowerShellVersion = engineKey.GetValue(RegistryStrings.MonadEngine_MonadVersion) as string;
                    return s_windowsPowerShellVersion;
                }
            }

            return string.Empty;
        }
#endif

        internal static string DefaultPowerShellAppBase => GetApplicationBase(DefaultPowerShellShellID);

        internal static string GetApplicationBase(string shellId)
        {
            // Use the location of SMA.dll as the application base if it exists,
            // otherwise, use the base directory from `AppContext`.
            var baseDirectory = Path.GetDirectoryName(typeof(PSObject).Assembly.Location);
            if (string.IsNullOrEmpty(baseDirectory))
            {
                // Need to remove any trailing directory separator characters
                baseDirectory = AppContext.BaseDirectory.TrimEnd(Path.DirectorySeparatorChar);
            }

            return baseDirectory;
        }

        private static string[] s_productFolderDirectories;

        private static string[] GetProductFolderDirectories()
        {
            if (s_productFolderDirectories == null)
            {
                List<string> baseDirectories = new List<string>();

                // Retrieve the application base from the registry
                string appBase = Utils.DefaultPowerShellAppBase;
                if (!string.IsNullOrEmpty(appBase))
                {
                    baseDirectories.Add(appBase);
                }
#if !UNIX
                // Now add the two variations of System32