From 952547c4fc0e296ca7196f10fca923d9d578cc4d Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Tue, 10 Mar 2020 12:22:30 -0700 Subject: [PATCH 1/3] Use Assembly.LoadFile in WinPS --- .../EditorServicesLoader.cs | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/PowerShellEditorServices.Hosting/EditorServicesLoader.cs b/src/PowerShellEditorServices.Hosting/EditorServicesLoader.cs index 7c69a895d..999ab3505 100644 --- a/src/PowerShellEditorServices.Hosting/EditorServicesLoader.cs +++ b/src/PowerShellEditorServices.Hosting/EditorServicesLoader.cs @@ -117,7 +117,7 @@ public static EditorServicesLoader Create( { logger.Log( PsesLogLevel.Diagnostic, - $"Loaded {args.LoadedAssembly.GetName()}"); + $"Loaded '{args.LoadedAssembly.GetName()}' from '{args.LoadedAssembly.Location}'"); }; } @@ -134,7 +134,7 @@ public static EditorServicesLoader Create( if (File.Exists(baseDirAsmPath)) { logger.Log(PsesLogLevel.Diagnostic, $"Loading {args.Name} from PSES base dir into LoadFrom context"); - return Assembly.LoadFrom(baseDirAsmPath); + return Assembly.LoadFile(baseDirAsmPath); } // Then look in the shared .NET Standard directory @@ -142,7 +142,7 @@ public static EditorServicesLoader Create( if (File.Exists(asmPath)) { logger.Log(PsesLogLevel.Diagnostic, $"Loading {args.Name} from PSES dependency dir into LoadFrom context"); - return Assembly.LoadFrom(asmPath); + return Assembly.LoadFile(asmPath); } return null; @@ -406,5 +406,28 @@ private void ValidateConfiguration() throw new ArgumentNullException(nameof(_hostConfig.PSHost)); } } + +#if !CoreCLR + private static void LoadAllAssembliesInDirectory(HostLogger logger, string directoryPath) + { + foreach (string asmPath in Directory.GetFiles(directoryPath, "*.dll")) + { + Assembly result = null; + try + { + result = Assembly.LoadFile(asmPath); + } + catch (Exception e) + { + logger.Log(PsesLogLevel.Diagnostic, $"Exception trying to load '{asmPath}':\n{e}"); + } + + if (result == null) + { + logger.Log(PsesLogLevel.Diagnostic, $"Loading assembly '{asmPath}' returned null"); + } + } + } +#endif } } From 3953e2c31fdc6ff20e2ca6cb583470bf61b1ff7f Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Tue, 10 Mar 2020 12:30:08 -0700 Subject: [PATCH 2/3] Remove vestigial method --- .../EditorServicesLoader.cs | 23 ------------------- 1 file changed, 23 deletions(-) diff --git a/src/PowerShellEditorServices.Hosting/EditorServicesLoader.cs b/src/PowerShellEditorServices.Hosting/EditorServicesLoader.cs index 999ab3505..6cf13fc61 100644 --- a/src/PowerShellEditorServices.Hosting/EditorServicesLoader.cs +++ b/src/PowerShellEditorServices.Hosting/EditorServicesLoader.cs @@ -406,28 +406,5 @@ private void ValidateConfiguration() throw new ArgumentNullException(nameof(_hostConfig.PSHost)); } } - -#if !CoreCLR - private static void LoadAllAssembliesInDirectory(HostLogger logger, string directoryPath) - { - foreach (string asmPath in Directory.GetFiles(directoryPath, "*.dll")) - { - Assembly result = null; - try - { - result = Assembly.LoadFile(asmPath); - } - catch (Exception e) - { - logger.Log(PsesLogLevel.Diagnostic, $"Exception trying to load '{asmPath}':\n{e}"); - } - - if (result == null) - { - logger.Log(PsesLogLevel.Diagnostic, $"Loading assembly '{asmPath}' returned null"); - } - } - } -#endif } } From 862b238ea25cee308c1f6fef25994a5e9116aecd Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 11 Mar 2020 12:05:27 -0700 Subject: [PATCH 3/3] Improve log message --- src/PowerShellEditorServices.Hosting/EditorServicesLoader.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PowerShellEditorServices.Hosting/EditorServicesLoader.cs b/src/PowerShellEditorServices.Hosting/EditorServicesLoader.cs index 6cf13fc61..370dd6e96 100644 --- a/src/PowerShellEditorServices.Hosting/EditorServicesLoader.cs +++ b/src/PowerShellEditorServices.Hosting/EditorServicesLoader.cs @@ -133,7 +133,7 @@ public static EditorServicesLoader Create( string baseDirAsmPath = Path.Combine(s_psesBaseDirPath, dllName); if (File.Exists(baseDirAsmPath)) { - logger.Log(PsesLogLevel.Diagnostic, $"Loading {args.Name} from PSES base dir into LoadFrom context"); + logger.Log(PsesLogLevel.Diagnostic, $"Loading {args.Name} from PSES base dir into LoadFile context"); return Assembly.LoadFile(baseDirAsmPath); } @@ -141,7 +141,7 @@ public static EditorServicesLoader Create( string asmPath = Path.Combine(s_psesDependencyDirPath, dllName); if (File.Exists(asmPath)) { - logger.Log(PsesLogLevel.Diagnostic, $"Loading {args.Name} from PSES dependency dir into LoadFrom context"); + logger.Log(PsesLogLevel.Diagnostic, $"Loading {args.Name} from PSES dependency dir into LoadFile context"); return Assembly.LoadFile(asmPath); }