diff --git a/ICSharpCode.Decompiler/Metadata/UniversalAssemblyResolver.cs b/ICSharpCode.Decompiler/Metadata/UniversalAssemblyResolver.cs index 2cbaa95eb..eeafad3f0 100644 --- a/ICSharpCode.Decompiler/Metadata/UniversalAssemblyResolver.cs +++ b/ICSharpCode.Decompiler/Metadata/UniversalAssemblyResolver.cs @@ -29,6 +29,18 @@ namespace ICSharpCode.Decompiler.Metadata // This inspired by Mono.Cecil's BaseAssemblyResolver/DefaultAssemblyResolver. public class UniversalAssemblyResolver : IAssemblyResolver { + static UniversalAssemblyResolver() + { + // TODO : test whether this works with Mono on *Windows*, not sure if we'll + // ever need this... + if (Type.GetType("Mono.Runtime") != null) + decompilerRuntime = DecompilerRuntime.Mono; + else if (Environment.OSVersion.Platform == PlatformID.Unix) + decompilerRuntime = DecompilerRuntime.Mono; + else if (typeof(object).Assembly.GetName().Name == "System.Private.CoreLib") + decompilerRuntime = DecompilerRuntime.NETCoreApp; + } + DotNetCorePathFinder dotNetCorePathFinder; readonly bool throwOnError; readonly PEStreamOptions streamOptions; @@ -38,21 +50,7 @@ namespace ICSharpCode.Decompiler.Metadata readonly List directories = new List(); readonly List gac_paths = GetGacPaths(); HashSet targetFrameworkSearchPaths; - - /// - /// Detect whether we're in a Mono environment. - /// - /// This is used whenever we're trying to decompile a plain old .NET framework assembly on Unix. - static bool DetectMono() - { - // TODO : test whether this works with Mono on *Windows*, not sure if we'll - // ever need this... - if (Type.GetType("Mono.Runtime") != null) - return true; - if (Environment.OSVersion.Platform == PlatformID.Unix) - return true; - return false; - } + static readonly DecompilerRuntime decompilerRuntime; public void AddSearchDirectory(string directory) { @@ -77,6 +75,13 @@ namespace ICSharpCode.Decompiler.Metadata Silverlight } + enum DecompilerRuntime + { + NETFramework, + NETCoreApp, + Mono + } + string targetFramework; TargetFrameworkIdentifier targetFrameworkIdentifier; Version targetFrameworkVersion; @@ -291,7 +296,7 @@ namespace ICSharpCode.Decompiler.Metadata return assembly; var framework_dir = Path.GetDirectoryName(typeof(object).Module.FullyQualifiedName); - var framework_dirs = DetectMono() + var framework_dirs = decompilerRuntime == DecompilerRuntime.Mono ? new[] { framework_dir, Path.Combine(framework_dir, "Facades") } : new[] { framework_dir }; @@ -367,11 +372,13 @@ namespace ICSharpCode.Decompiler.Metadata var version = reference.Version; var corlib = typeof(object).Assembly.GetName(); - if (corlib.Version == version || IsSpecialVersionOrRetargetable(reference)) - return typeof(object).Module.FullyQualifiedName; + if (decompilerRuntime != DecompilerRuntime.NETCoreApp) { + if (corlib.Version == version || IsSpecialVersionOrRetargetable(reference)) + return typeof(object).Module.FullyQualifiedName; + } string path; - if (DetectMono()) { + if (decompilerRuntime == DecompilerRuntime.Mono) { path = GetMonoMscorlibBasePath(version); } else { path = GetMscorlibBasePath(version, reference.PublicKeyToken.ToHexString(8)); @@ -460,7 +467,7 @@ namespace ICSharpCode.Decompiler.Metadata static List GetGacPaths() { - if (DetectMono()) + if (decompilerRuntime == DecompilerRuntime.Mono) return GetDefaultMonoGacPaths(); var paths = new List(2); @@ -510,7 +517,7 @@ namespace ICSharpCode.Decompiler.Metadata if (reference.PublicKeyToken == null || reference.PublicKeyToken.Length == 0) return null; - if (DetectMono()) + if (decompilerRuntime == DecompilerRuntime.Mono) return GetAssemblyInMonoGac(reference); return GetAssemblyInNetGac(reference);