Skip to content

Commit 3bb10b7

Browse files
authored
Loosen version comparisons in loading assemblies (#7042)
Fixes #6993 by matching the .NET Core runtime's behavior (>= requested version is a match).
1 parent 02bee81 commit 3bb10b7

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

src/Shared/CoreCLRAssemblyLoader.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,10 @@ private Assembly TryResolveAssemblyFromPaths(AssemblyLoadContext context, Assemb
164164
}
165165

166166
AssemblyName candidateAssemblyName = AssemblyLoadContext.GetAssemblyName(candidatePath);
167-
if (candidateAssemblyName.Version != assemblyName.Version)
167+
if (candidateAssemblyName.Version >= assemblyName.Version)
168168
{
169-
continue;
169+
return LoadAndCache(context, candidatePath);
170170
}
171-
172-
return LoadAndCache(context, candidatePath);
173171
}
174172
}
175173

src/Shared/MSBuildLoadContext.cs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,20 @@ public MSBuildLoadContext(string assemblyPath)
5353
// bare search directory if that fails.
5454
: new[] { assemblyName.CultureName, string.Empty })
5555
{
56-
var candidatePath = Path.Combine(_directory,
57-
cultureSubfolder,
58-
$"{assemblyName.Name}.dll");
56+
var candidatePath = Path.Combine(_directory,
57+
cultureSubfolder,
58+
$"{assemblyName.Name}.dll");
5959

60-
if (!FileSystems.Default.FileExists(candidatePath))
61-
{
62-
continue;
63-
}
64-
65-
AssemblyName candidateAssemblyName = AssemblyLoadContext.GetAssemblyName(candidatePath);
66-
if (candidateAssemblyName.Version != assemblyName.Version)
67-
{
68-
continue;
69-
}
60+
if (!FileSystems.Default.FileExists(candidatePath))
61+
{
62+
continue;
63+
}
7064

65+
AssemblyName candidateAssemblyName = AssemblyLoadContext.GetAssemblyName(candidatePath);
66+
if (candidateAssemblyName.Version >= assemblyName.Version)
67+
{
7168
return LoadFromAssemblyPath(candidatePath);
69+
}
7270
}
7371

7472
// If the Assembly is provided via a file path, the following rules are used to load the assembly:

0 commit comments

Comments
 (0)