Skip to content

Commit

Permalink
Give host ResolveAssemblyReference priority over reference paths
Browse files Browse the repository at this point in the history
The list of assembly files referenced by the template may contain
reference assemblies, which will fail to load. Letting the host attempt
to resolve the assembly first gives it an opportunity to resolve runtime
assemblies.

Ideally we would have a robust mechanism for resolving runtime
assemblies bue this will have to serve as a stopgap.
  • Loading branch information
mhutch committed Jan 10, 2024
1 parent 2aea692 commit ad28c47
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,20 @@ Assembly ResolveReferencedAssemblies (object sender, ResolveEventArgs args)
{
var asmName = new AssemblyName (args.Name);

// The list of assembly files referenced by the template may contain reference assemblies,
// which will fail to load. Letting the host attempt to resolve the assembly first
// gives it an opportunity to resolve runtime assemblies.
var path = resolveAssemblyReference (asmName.Name + ".dll");
if (File.Exists (path)) {
return Assembly.LoadFrom (path);
}

foreach (var asmFile in assemblyFiles) {
if (asmName.Name == Path.GetFileNameWithoutExtension (asmFile)) {
return Assembly.LoadFrom (asmFile);
}
}

var path = resolveAssemblyReference (asmName.Name + ".dll");
if (File.Exists (path)) {
return Assembly.LoadFrom (path);
}

return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ protected override Assembly Load (AssemblyName assemblyName)

Assembly ResolveAssembly (AssemblyLoadContext context, AssemblyName assemblyName)
{
// The list of assembly files referenced by the template may contain reference assemblies,
// which will fail to load. Letting the host attempt to resolve the assembly first
// gives it an opportunity to resolve runtime assemblies.
var path = host.ResolveAssemblyReference (assemblyName.Name + ".dll");
if (File.Exists (path)) {
return LoadFromAssemblyPath (path);
}

for (int i = 0; i < templateAssemblyFiles.Length; i++) {
var asmFile = templateAssemblyFiles[i];
if (asmFile is null) {
Expand All @@ -113,11 +121,6 @@ Assembly ResolveAssembly (AssemblyLoadContext context, AssemblyName assemblyName
}
}

var path = host.ResolveAssemblyReference (assemblyName.Name + ".dll");
if (File.Exists (path)) {
return LoadFromAssemblyPath (path);
}

return null;
}
}
Expand Down

0 comments on commit ad28c47

Please sign in to comment.