From 3de29c8d744f044876fce932659062794e40e322 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 1 Aug 2023 21:56:57 +0200 Subject: [PATCH] Fix #2891 Populate framework_dirs with the correct values depending on the current host runtime. --- .../Metadata/UniversalAssemblyResolver.cs | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/ICSharpCode.Decompiler/Metadata/UniversalAssemblyResolver.cs b/ICSharpCode.Decompiler/Metadata/UniversalAssemblyResolver.cs index 8b8575619e..92fff14b0a 100644 --- a/ICSharpCode.Decompiler/Metadata/UniversalAssemblyResolver.cs +++ b/ICSharpCode.Decompiler/Metadata/UniversalAssemblyResolver.cs @@ -404,10 +404,37 @@ string FindClosestVersionDirectory(string basePath, Version? version) if (assembly != null) return assembly; - var framework_dir = Path.GetDirectoryName(typeof(object).Module.FullyQualifiedName)!; - var framework_dirs = decompilerRuntime == DecompilerRuntime.Mono - ? new[] { framework_dir, Path.Combine(framework_dir, "Facades") } - : new[] { framework_dir }; + string[] framework_dirs; + string framework_dir; + + switch (decompilerRuntime) + { + case DecompilerRuntime.Mono: + framework_dir = Path.GetDirectoryName(typeof(object).Module.FullyQualifiedName)!; + framework_dirs = new[] { framework_dir, Path.Combine(framework_dir, "Facades") }; + break; + case DecompilerRuntime.NETCoreApp: + string windir; + try + { + windir = Environment.GetFolderPath(Environment.SpecialFolder.Windows); + if (string.IsNullOrEmpty(windir)) + { + goto default; + } + } + catch (PlatformNotSupportedException) + { + goto default; + } + framework_dir = Path.Combine(windir, "Microsoft.NET", "Framework64", "v4.0.30319"); + framework_dirs = new[] { framework_dir }; + break; + default: + framework_dir = Path.GetDirectoryName(typeof(object).Module.FullyQualifiedName)!; + framework_dirs = new[] { framework_dir }; + break; + } if (IsSpecialVersionOrRetargetable(name)) {