Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 59d0eff

Browse files
committed
ResolveSatelliteAssembly should ...
ResolveSatelliteAssembly should always be called on the ALC which loaded parentAssembly Simplify code. Add Debug.Assert
1 parent 9a81a9e commit 59d0eff

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

src/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.Unix.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,15 @@ public bool Equals(ref ReadOnlySpan<char> entryName)
114114
if (parentAssembly == null)
115115
return null;
116116

117-
AssemblyLoadContext? parentAlc = GetLoadContext(parentAssembly);
118-
119-
if (parentAlc == null)
120-
return null;
117+
// ResolveSatelliteAssembly should always be called on the ALC which loaded parentAssembly
118+
Debug.Assert(this == GetLoadContext(parentAssembly));
121119

122120
string parentDirectory = Path.GetDirectoryName(parentAssembly.Location)!;
123121

124122
string assemblyPath = $"{parentDirectory}/{cultureName}/{assemblyName.Name}.dll";
125123
if (Internal.IO.File.InternalExists(assemblyPath))
126124
{
127-
return parentAlc.LoadFromAssemblyPath(assemblyPath);
125+
return LoadFromAssemblyPath(assemblyPath);
128126
}
129127
else if (Path.IsCaseSensitive)
130128
{
@@ -134,7 +132,7 @@ public bool Equals(ref ReadOnlySpan<char> entryName)
134132
{
135133
assemblyPath = $"{parentDirectory}/{caseInsensitiveCultureName}/{assemblyName.Name}.dll";
136134
if (Internal.IO.File.InternalExists(assemblyPath))
137-
return parentAlc.LoadFromAssemblyPath(assemblyPath);
135+
return LoadFromAssemblyPath(assemblyPath);
138136
}
139137
}
140138
return null;

src/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.Windows.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,15 @@ public partial class AssemblyLoadContext
2727
if (parentAssembly == null)
2828
return null;
2929

30-
AssemblyLoadContext? parentAlc = GetLoadContext(parentAssembly);
31-
32-
if (parentAlc == null)
33-
return null;
30+
// ResolveSatelliteAssembly should always be called on the ALC which loaded parentAssembly
31+
Debug.Assert(this == GetLoadContext(parentAssembly));
3432

3533
string parentDirectory = Path.GetDirectoryName(parentAssembly.Location)!;
3634

37-
string assemblyPath = Path.Combine(parentDirectory, dir, $"{assemblyName.Name}.dll");
35+
string assemblyPath = Path.Combine(parentDirectory, cultureName, $"{assemblyName.Name}.dll");
3836
if (Internal.IO.File.InternalExists(assemblyPath))
3937
{
40-
return parentAlc.LoadFromAssemblyPath(assemblyPath);
38+
return LoadFromAssemblyPath(assemblyPath);
4139
}
4240

4341
return null;

0 commit comments

Comments
 (0)