Browse Source

Resolve assembly references against the host runtime directory as a last resort

Hosts without a .NET Framework installation (e.g. Linux and macOS) have
no GAC; the only system-wide assembly store there is the shared-framework
directory of the runtime executing the decompiler, and
UniversalAssemblyResolver only consulted it through the version <= 4.0
legacy fallback. This made e.g. the type-forwards of a netstandard facade
(pointing to a versioned System.Runtime) unresolvable, which left
well-known types like Nullable<T> without a definition and among other
things misaligned nullability decoding (Nullable<T> occupies no slot in
the nullable metadata, so it must be recognized).

On Windows nothing the GAC answered changes; the new fallback only adds
resolutions that previously failed outright.

Assisted-by: Claude:claude-fable-5:Claude Code
pull/3773/head
Siegfried Pammer 4 weeks ago committed by Siegfried Pammer
parent
commit
701edf3a8c
  1. 16
      ICSharpCode.Decompiler/Metadata/UniversalAssemblyResolver.cs

16
ICSharpCode.Decompiler/Metadata/UniversalAssemblyResolver.cs

@ -71,6 +71,8 @@ namespace ICSharpCode.Decompiler.Metadata @@ -71,6 +71,8 @@ namespace ICSharpCode.Decompiler.Metadata
decompilerRuntime = DecompilerRuntime.NETCoreApp;
else if (Environment.OSVersion.Platform == PlatformID.Unix)
decompilerRuntime = DecompilerRuntime.Mono;
else
decompilerRuntime = DecompilerRuntime.NETFramework;
}
readonly Lazy<DotNetCorePathFinder> dotNetCorePathFinder;
@ -464,6 +466,20 @@ namespace ICSharpCode.Decompiler.Metadata @@ -464,6 +466,20 @@ namespace ICSharpCode.Decompiler.Metadata
return assembly;
}
if (decompilerRuntime == DecompilerRuntime.NETCoreApp)
{
// Hosts without a .NET Framework installation (e.g. Linux, macOS) have no GAC;
// the only system-wide assembly store there is the shared-framework directory
// of the runtime executing the decompiler. Search it as the last resort,
// regardless of the requested version (the runtime itself rolls forward in the
// same way). Without this, e.g. the type-forwards of a netstandard facade
// (pointing to a versioned System.Runtime) are unresolvable on such hosts.
string runtimeDir = Path.GetDirectoryName(typeof(object).Module.FullyQualifiedName)!;
assembly = SearchDirectory(name, runtimeDir);
if (assembly != null)
return assembly;
}
if (throwOnError)
throw new ResolutionException(name, null, null);
return null;

Loading…
Cancel
Save