From ef9a37df7927bb5ba40cff6fdeef8d84e7c093fa Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Sat, 21 May 2016 08:35:27 -0700 Subject: [PATCH] Rename PowerShellAssemblyLoadContext to PowerShellAssemblyLoader PowerShellAssemblyLoadContext does not inherit from AssemblyLoadContext. Rename it to avoid confusion. --- ...Context.cs => PowerShellAssemblyLoader.cs} | 16 +++++++------- .../CorePsTypeCatalog.cs | 2 +- .../resources/ParserStrings.resx | 2 +- .../utils/ClrFacade.cs | 22 +++++++++---------- src/TypeCatalogGen/TypeCatalogGen.cs | 8 +++---- 5 files changed, 25 insertions(+), 25 deletions(-) rename src/Microsoft.PowerShell.CoreCLR.AssemblyLoadContext/CoreCLR/{CorePsAssemblyLoadContext.cs => PowerShellAssemblyLoader.cs} (97%) diff --git a/src/Microsoft.PowerShell.CoreCLR.AssemblyLoadContext/CoreCLR/CorePsAssemblyLoadContext.cs b/src/Microsoft.PowerShell.CoreCLR.AssemblyLoadContext/CoreCLR/PowerShellAssemblyLoader.cs similarity index 97% rename from src/Microsoft.PowerShell.CoreCLR.AssemblyLoadContext/CoreCLR/CorePsAssemblyLoadContext.cs rename to src/Microsoft.PowerShell.CoreCLR.AssemblyLoadContext/CoreCLR/PowerShellAssemblyLoader.cs index 2a767452d2..418ec2b8a3 100644 --- a/src/Microsoft.PowerShell.CoreCLR.AssemblyLoadContext/CoreCLR/CorePsAssemblyLoadContext.cs +++ b/src/Microsoft.PowerShell.CoreCLR.AssemblyLoadContext/CoreCLR/PowerShellAssemblyLoader.cs @@ -17,12 +17,12 @@ namespace System.Management.Automation /// /// The powershell custom assembly loader implementation /// - 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. /// - 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 /// - /// The global instance of PowerShellAssemblyLoadContext + /// The global instance of PowerShellAssemblyLoader /// - internal static PowerShellAssemblyLoadContext Instance { get; set; } + internal static PowerShellAssemblyLoader Instance { get; set; } /// /// Implement the AssemblyLoadContext.Resolving event handler. Search the requested assembly in probing paths. @@ -510,7 +510,7 @@ namespace System.Management.Automation } /// - /// 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. /// public class PowerShellAssemblyLoadContextInitializer @@ -529,9 +529,9 @@ namespace System.Management.Automation /// 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); } } } diff --git a/src/Microsoft.PowerShell.CoreCLR.AssemblyLoadContext/CorePsTypeCatalog.cs b/src/Microsoft.PowerShell.CoreCLR.AssemblyLoadContext/CorePsTypeCatalog.cs index d00fa92ccf..7a5acf16f1 100644 --- a/src/Microsoft.PowerShell.CoreCLR.AssemblyLoadContext/CorePsTypeCatalog.cs +++ b/src/Microsoft.PowerShell.CoreCLR.AssemblyLoadContext/CorePsTypeCatalog.cs @@ -10,7 +10,7 @@ using System.Collections.Generic; namespace System.Management.Automation { - internal partial class PowerShellAssemblyLoadContext + internal partial class PowerShellAssemblyLoader { private Dictionary InitializeTypeCatalog() { diff --git a/src/System.Management.Automation/resources/ParserStrings.resx b/src/System.Management.Automation/resources/ParserStrings.resx index ba99c3d0da..807450a9d7 100644 --- a/src/System.Management.Automation/resources/ParserStrings.resx +++ b/src/System.Management.Automation/resources/ParserStrings.resx @@ -1352,7 +1352,7 @@ ModuleVersion : Version of module to import. If used, ModuleName must represent Cannot run a document in PowerShell Core: {0}. - The default AssemblyLoadContext in use is invalid. The default AssemblyLoadContext for PowerShell Core should be of type 'PowerShellAssemblyLoadContext'. + The default AssemblyLoadContext in use is invalid. The default AssemblyLoadContext for PowerShell Core should be of type 'PowerShellAssemblyLoader'. Multiple type constraints are not allowed on a method parameter. diff --git a/src/System.Management.Automation/utils/ClrFacade.cs b/src/System.Management.Automation/utils/ClrFacade.cs index faeda630f8..744e2bb5e2 100644 --- a/src/System.Management.Automation/utils/ClrFacade.cs +++ b/src/System.Management.Automation/utils/ClrFacade.cs @@ -276,7 +276,7 @@ namespace System.Management.Automation internal static IEnumerable 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 /// 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 /// internal static IEnumerable GetAvailableCoreClrDotNetTypes() { - var psAssemblyLoader = GetAssemblyLoadContext(); + var psAssemblyLoader = GetAssemblyLoader(); return psAssemblyLoader.GetAvailableDotNetTypes(); } /// /// Get the powershell custom AssemblyLoadContext. /// - 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 /// diff --git a/src/TypeCatalogGen/TypeCatalogGen.cs b/src/TypeCatalogGen/TypeCatalogGen.cs index ecaff01c02..5aa7a44f4a 100644 --- a/src/TypeCatalogGen/TypeCatalogGen.cs +++ b/src/TypeCatalogGen/TypeCatalogGen.cs @@ -41,7 +41,7 @@ Usage: TypeCatalogGen.exe <{0}> <{1}> /* * Go through all reference assemblies of .NET Core and generate the type catalog -> Dictionary - * 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); } /// @@ -272,7 +272,7 @@ Usage: TypeCatalogGen.exe <{0}> <{1}> /// /// Generate the CSharp source code that initialize the type catalog. /// - private static void WritePowerShellAssemblyLoadContextPartialClass(string targetFilePath, Dictionary typeNameToAssemblyMap) + private static void WritePowerShellAssemblyLoaderPartialClass(string targetFilePath, Dictionary 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 InitializeTypeCatalog() {{