Skip to content

Commit 3de29c8

Browse files
Fix #2891 Populate framework_dirs with the correct values depending on the current host runtime.
1 parent d1ac27e commit 3de29c8

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

ICSharpCode.Decompiler/Metadata/UniversalAssemblyResolver.cs

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,10 +404,37 @@ string FindClosestVersionDirectory(string basePath, Version? version)
404404
if (assembly != null)
405405
return assembly;
406406

407-
var framework_dir = Path.GetDirectoryName(typeof(object).Module.FullyQualifiedName)!;
408-
var framework_dirs = decompilerRuntime == DecompilerRuntime.Mono
409-
? new[] { framework_dir, Path.Combine(framework_dir, "Facades") }
410-
: new[] { framework_dir };
407+
string[] framework_dirs;
408+
string framework_dir;
409+
410+
switch (decompilerRuntime)
411+
{
412+
case DecompilerRuntime.Mono:
413+
framework_dir = Path.GetDirectoryName(typeof(object).Module.FullyQualifiedName)!;
414+
framework_dirs = new[] { framework_dir, Path.Combine(framework_dir, "Facades") };
415+
break;
416+
case DecompilerRuntime.NETCoreApp:
417+
string windir;
418+
try
419+
{
420+
windir = Environment.GetFolderPath(Environment.SpecialFolder.Windows);
421+
if (string.IsNullOrEmpty(windir))
422+
{
423+
goto default;
424+
}
425+
}
426+
catch (PlatformNotSupportedException)
427+
{
428+
goto default;
429+
}
430+
framework_dir = Path.Combine(windir, "Microsoft.NET", "Framework64", "v4.0.30319");
431+
framework_dirs = new[] { framework_dir };
432+
break;
433+
default:
434+
framework_dir = Path.GetDirectoryName(typeof(object).Module.FullyQualifiedName)!;
435+
framework_dirs = new[] { framework_dir };
436+
break;
437+
}
411438

412439
if (IsSpecialVersionOrRetargetable(name))
413440
{

0 commit comments

Comments
 (0)