Rename PowerShellAssemblyLoadContext to PowerShellAssemblyLoader

PowerShellAssemblyLoadContext does not inherit from AssemblyLoadContext. Rename
it to avoid confusion.
This commit is contained in:
Jan Kotas
2016-05-24 09:55:04 -07:00
committed by Andrew Schwartzmeyer
parent 44ba0bb28f
commit ef9a37df79
5 changed files with 25 additions and 25 deletions
@@ -17,12 +17,12 @@ namespace System.Management.Automation
/// <summary>
/// The powershell custom assembly loader implementation
/// </summary>
internal partial class PowerShellAssemblyLoadContext
internal partial class PowerShellAssemblyLoader
{
#region Resource_Strings
// We cannot use a satellite resources.dll to store resource strings for Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.dll. This is because when retrieving resource strings, ResourceManager
// tries to load the satellite resources.dll using a probing approach, which will cause an infinite loop to PowerShellAssemblyLoadContext.Load(AssemblyName).
// tries to load the satellite resources.dll using a probing approach, which will cause an infinite loop to PowerShellAssemblyLoader.Load(AssemblyName).
// Take the 'en-US' culture as an example. When retrieving resource string to construct an exception, ResourceManager calls Assembly.Load(..) in the following order to load the resource dll:
// 1. Load assembly with culture 'en-US' (Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.resources, Version=3.0.0.0, Culture=en-US, PublicKeyToken=31bf3856ad364e35)
// 2. Load assembly with culture 'en' (Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.resources, Version=3.0.0.0, Culture=en, PublicKeyToken=31bf3856ad364e35)
@@ -44,7 +44,7 @@ namespace System.Management.Automation
/// Base directory paths that are separated by semicolon ';'.
/// They will be the default paths to probe assemblies.
/// </param>
internal PowerShellAssemblyLoadContext(string basePaths)
internal PowerShellAssemblyLoader(string basePaths)
{
#region Validation
this.basePaths = basePaths.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
@@ -117,9 +117,9 @@ namespace System.Management.Automation
#region Protected_Internal_Methods
/// <summary>
/// The global instance of PowerShellAssemblyLoadContext
/// The global instance of PowerShellAssemblyLoader
/// </summary>
internal static PowerShellAssemblyLoadContext Instance { get; set; }
internal static PowerShellAssemblyLoader Instance { get; set; }
/// <summary>
/// Implement the AssemblyLoadContext.Resolving event handler. Search the requested assembly in probing paths.
@@ -510,7 +510,7 @@ namespace System.Management.Automation
}
/// <summary>
/// Set an instance of PowerShellAssemblyLoadContext to be the default Assembly Load Context.
/// Set an instance of PowerShellAssemblyLoader to be the default Assembly Load Context.
/// This is the managed entry point for Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.dll.
/// </summary>
public class PowerShellAssemblyLoadContextInitializer
@@ -529,9 +529,9 @@ namespace System.Management.Automation
/// </summary>
public static void SetPowerShellAssemblyLoadContext([MarshalAs(stringType)]string basePaths)
{
if (PowerShellAssemblyLoadContext.Instance == null)
if (PowerShellAssemblyLoader.Instance == null)
{
PowerShellAssemblyLoadContext.Instance = new PowerShellAssemblyLoadContext(basePaths);
PowerShellAssemblyLoader.Instance = new PowerShellAssemblyLoader(basePaths);
}
}
}
@@ -10,7 +10,7 @@ using System.Collections.Generic;
namespace System.Management.Automation
{
internal partial class PowerShellAssemblyLoadContext
internal partial class PowerShellAssemblyLoader
{
private Dictionary<string, string> InitializeTypeCatalog()
{
@@ -1352,7 +1352,7 @@ ModuleVersion : Version of module to import. If used, ModuleName must represent
<value>Cannot run a document in PowerShell Core: {0}.</value>
</data>
<data name="InvalidAssemblyLoadContextInUse" xml:space="preserve">
<value>The default AssemblyLoadContext in use is invalid. The default AssemblyLoadContext for PowerShell Core should be of type 'PowerShellAssemblyLoadContext'.</value>
<value>The default AssemblyLoadContext in use is invalid. The default AssemblyLoadContext for PowerShell Core should be of type 'PowerShellAssemblyLoader'.</value>
</data>
<data name="MultipleTypeConstraintsOnMethodParam" xml:space="preserve">
<value>Multiple type constraints are not allowed on a method parameter.</value>
@@ -276,7 +276,7 @@ namespace System.Management.Automation
internal static IEnumerable<Assembly> GetAssemblies(string namespaceQualifiedTypeName = null)
{
#if CORECLR
var psAssemblyLoader = GetAssemblyLoadContext();
var psAssemblyLoader = GetAssemblyLoader();
return psAssemblyLoader.GetAssemblies(namespaceQualifiedTypeName);
#else
return AppDomain.CurrentDomain.GetAssemblies().Where(a => !(a.FullName.Length > 0 && a.FullName[0] == FIRST_CHAR_PSASSEMBLY_MARK));
@@ -290,7 +290,7 @@ namespace System.Management.Automation
internal static Assembly LoadFrom(string assemblyPath)
{
#if CORECLR
var psAssemblyLoader = GetAssemblyLoadContext();
var psAssemblyLoader = GetAssemblyLoader();
return psAssemblyLoader.LoadFrom(assemblyPath);
#else
return Assembly.LoadFrom(assemblyPath);
@@ -303,7 +303,7 @@ namespace System.Management.Automation
/// </summary>
internal static Assembly LoadFrom(Stream assembly)
{
var psAssemblyLoader = GetAssemblyLoadContext();
var psAssemblyLoader = GetAssemblyLoader();
return psAssemblyLoader.LoadFrom(assembly);
}
#endif
@@ -315,7 +315,7 @@ namespace System.Management.Automation
internal static Assembly Load(AssemblyName assembly)
{
#if CORECLR
var psAssemblyLoader = GetAssemblyLoadContext();
var psAssemblyLoader = GetAssemblyLoader();
return psAssemblyLoader.LoadFromAssemblyName(assembly);
#else
return Assembly.Load(assembly);
@@ -328,7 +328,7 @@ namespace System.Management.Automation
internal static Assembly Load(string assembly)
{
#if CORECLR
var psAssemblyLoader = GetAssemblyLoadContext();
var psAssemblyLoader = GetAssemblyLoader();
return psAssemblyLoader.LoadFromAssemblyName(new AssemblyName(assembly));
#else
return Assembly.Load(assembly);
@@ -347,7 +347,7 @@ namespace System.Management.Automation
#if CORECLR
// Create the enum type and add the dynamic assembly to assembly cache.
TypeInfo enumTypeinfo = enumBuilder.CreateTypeInfo();
var psAssemblyLoader = GetAssemblyLoadContext();
var psAssemblyLoader = GetAssemblyLoader();
psAssemblyLoader.TryAddAssemblyToCache(enumTypeinfo.Assembly);
#else
enumBuilder.CreateTypeInfo();
@@ -370,7 +370,7 @@ namespace System.Management.Automation
throw new ArgumentNullException("assemblyShortName");
}
var psAssemblyLoader = GetAssemblyLoadContext();
var psAssemblyLoader = GetAssemblyLoader();
return psAssemblyLoader.ProbeAssemblyFileForMetadataAnalysis(assemblyShortName, additionalSearchPath);
}
@@ -380,22 +380,22 @@ namespace System.Management.Automation
/// </summary>
internal static IEnumerable<string> GetAvailableCoreClrDotNetTypes()
{
var psAssemblyLoader = GetAssemblyLoadContext();
var psAssemblyLoader = GetAssemblyLoader();
return psAssemblyLoader.GetAvailableDotNetTypes();
}
/// <summary>
/// Get the powershell custom AssemblyLoadContext.
/// </summary>
internal static PowerShellAssemblyLoadContext GetAssemblyLoadContext()
internal static PowerShellAssemblyLoader GetAssemblyLoader()
{
if (_psLoadContext == null)
{
_psLoadContext = PowerShellAssemblyLoadContext.Instance;
_psLoadContext = PowerShellAssemblyLoader.Instance;
}
return _psLoadContext;
}
private static volatile PowerShellAssemblyLoadContext _psLoadContext;
private static volatile PowerShellAssemblyLoader _psLoadContext;
#endif
/// <summary>
+4 -4
View File
@@ -41,7 +41,7 @@ Usage: TypeCatalogGen.exe <{0}> <{1}>
/*
* Go through all reference assemblies of .NET Core and generate the type catalog -> Dictionary<NamespaceQualifiedTypeName, TPAStrongName>
* Then auto-generate the partial class 'PowerShellAssemblyLoadContext' that has the code to initialize the type catalog cache.
* Then auto-generate the partial class 'PowerShellAssemblyLoader' that has the code to initialize the type catalog cache.
*
* In CoreCLR, there is no way to get all loaded TPA assemblies (.NET Framework Assemblies). In order to get type based on type name, powershell needs to know what .NET
* types are available and in which TPA assemblies. So we have to generate the type catalog based on the reference assemblies of .NET Core.
@@ -105,7 +105,7 @@ Usage: TypeCatalogGen.exe <{0}> <{1}>
}
}
WritePowerShellAssemblyLoadContextPartialClass(targetFilePath, typeNameToAssemblyMap);
WritePowerShellAssemblyLoaderPartialClass(targetFilePath, typeNameToAssemblyMap);
}
/// <summary>
@@ -272,7 +272,7 @@ Usage: TypeCatalogGen.exe <{0}> <{1}>
/// <summary>
/// Generate the CSharp source code that initialize the type catalog.
/// </summary>
private static void WritePowerShellAssemblyLoadContextPartialClass(string targetFilePath, Dictionary<string, string> typeNameToAssemblyMap)
private static void WritePowerShellAssemblyLoaderPartialClass(string targetFilePath, Dictionary<string, string> typeNameToAssemblyMap)
{
const string SourceFormat = " typeCatalog[\"{0}\"] = \"{1}\";";
const string SourceHead = @"//
@@ -287,7 +287,7 @@ using System.Collections.Generic;
namespace System.Management.Automation
{{
internal partial class PowerShellAssemblyLoadContext
internal partial class PowerShellAssemblyLoader
{{
private Dictionary<string, string> InitializeTypeCatalog()
{{