Skip to content

Commit 2360d1e

Browse files
committed
Filter runtime assemblies out of custom context
1 parent 5a29df5 commit 2360d1e

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

src/Microsoft.PowerShell.CoreCLR.AssemblyLoadContext/CoreCLR/CorePsAssemblyLoadContext.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Collections.Concurrent;
99
using System.Collections.Generic;
1010
using System.Globalization;
11+
using System.Linq;
1112
using System.Runtime.InteropServices;
1213
using System.Reflection;
1314
using System.Reflection.Metadata;
@@ -91,6 +92,9 @@ private PowerShellAssemblyLoadContext(string basePaths, bool useResolvingHandler
9192

9293
trace = System.Environment.GetEnvironmentVariable("ALC_TRACE") == "1";
9394

95+
if (trace)
96+
Console.WriteLine(" == APPBASE == {0}", basePaths);
97+
9498
this.basePaths = basePaths.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
9599
for (int i = 0; i < this.basePaths.Length; i++)
96100
{
@@ -195,12 +199,17 @@ protected override Assembly Load(AssemblyName assemblyName)
195199

196200
if (trace)
197201
System.Console.WriteLine("== LC1 == Requesting: {0}", assemblyName.FullName);
202+
198203
if (filterSet == null)
199204
{
200-
filterSet = new HashSet<string>(coreClrTypeCatalog.Values);
205+
// We exclude the assemblies included in the type catalog as there appears to be a
206+
// bug in .NET with method resolution with system libraries are loaded by our
207+
// context and not the default. We use the short name because some packages have
208+
// inconsistent verions between reference and runtime assemblies.
209+
filterSet = new HashSet<string>(from x in coreClrTypeCatalog.Values select x.Substring(0, x.IndexOf(",")));
201210
}
202-
203-
if (filterSet.Contains(assemblyName.FullName))
211+
212+
if (filterSet.Contains(assemblyName.Name))
204213
{
205214
if (trace)
206215
System.Console.WriteLine(" ++ Return null from Load override");
@@ -463,7 +472,7 @@ internal IEnumerable<string> GetAvailableDotNetTypes()
463472
}
464473

465474
/// <summary>
466-
/// Set the profile optimization root on the approprite load context
475+
/// Set the profile optimization root on the appropriate load context
467476
/// </summary>
468477
internal void SetProfileOptimizationRootImpl(string directoryPath)
469478
{
@@ -472,7 +481,7 @@ internal void SetProfileOptimizationRootImpl(string directoryPath)
472481
}
473482

474483
/// <summary>
475-
/// Start the profile optimization on the approprite load context
484+
/// Start the profile optimization on the appropriate load context
476485
/// </summary>
477486
internal void StartProfileOptimizationImpl(string profile)
478487
{

src/powershell/Program.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ public static int Main(string[] args)
2424
#if CORECLR
2525
// Open PowerShell has to set the ALC here, since we don't own the native host
2626
string appBase = System.IO.Path.GetDirectoryName(typeof(ManagedPSEntry).GetTypeInfo().Assembly.Location);
27-
Console.WriteLine(" == APPBASE == {0}", appBase);
28-
//Console.Read();
2927
return (int)PowerShellAssemblyLoadContextInitializer.
3028
InitializeAndCallEntryMethod(
3129
appBase,

0 commit comments

Comments
 (0)