Skip to content

Commit

Permalink
In TestAssemblyResolver the DependencyContext can be null
Browse files Browse the repository at this point in the history
  • Loading branch information
manfred-brands committed Dec 31, 2024
1 parent b18b1ee commit 2667029
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ bool FileMatchesAssembly(string fileName) =>

public class RuntimeLibrariesStrategy : ResolutionStrategy
{
private DependencyContext _dependencyContext;
private DependencyContext? _dependencyContext;
private readonly ICompilationAssemblyResolver _assemblyResolver;

public RuntimeLibrariesStrategy(AssemblyLoadContext loadContext, string testAssemblyPath)
{
_dependencyContext = DependencyContext.Load(loadContext.LoadFromAssemblyPath(testAssemblyPath)).ShouldNotBeNull();
_dependencyContext = DependencyContext.Load(loadContext.LoadFromAssemblyPath(testAssemblyPath));

_assemblyResolver = new CompositeCompilationAssemblyResolver(new ICompilationAssemblyResolver[]
{
Expand All @@ -170,6 +170,13 @@ public RuntimeLibrariesStrategy(AssemblyLoadContext loadContext, string testAsse
public override bool TryToResolve(
AssemblyLoadContext loadContext, AssemblyName assemblyName, [NotNullWhen(true)] out Assembly? loadedAssembly)
{
if (_dependencyContext == null)
{
// TODO: Is this the intended behavior?
loadedAssembly = null;
return false;
}

foreach (var library in _dependencyContext.RuntimeLibraries)
{
var wrapper = new CompilationLibrary(
Expand Down

0 comments on commit 2667029

Please sign in to comment.