Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions src/PowerShellEditorServices.Hosting/EditorServicesLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public sealed class EditorServicesLoader : IDisposable
{
private const int Net461Version = 394254;

#if !CoreCLR
private static readonly string s_psesBaseDirPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
#endif

private static readonly string s_psesDependencyDirPath = Path.GetFullPath(
Path.Combine(
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
Expand Down Expand Up @@ -72,7 +76,6 @@ public static EditorServicesLoader Create(

#if CoreCLR
// In .NET Core, we add an event here to redirect dependency loading to the new AssemblyLoadContext we load PSES' dependencies into

logger.Log(PsesLogLevel.Verbose, "Adding AssemblyResolve event handler for new AssemblyLoadContext dependency loading");

var psesLoadContext = new PsesLoadContext(s_psesDependencyDirPath);
Expand Down Expand Up @@ -123,14 +126,25 @@ public static EditorServicesLoader Create(
logger.Log(PsesLogLevel.Diagnostic, $"Assembly resolve event fired for {args.Name}");

var asmName = new AssemblyName(args.Name);
string asmPath = Path.Combine(s_psesDependencyDirPath, $"{asmName.Name}.dll");
if (!File.Exists(asmPath))
var dllName = $"{asmName.Name}.dll";

// First look for the required assembly in the .NET Framework DLL dir
string baseDirAsmPath = Path.Combine(s_psesBaseDirPath, dllName);
if (File.Exists(baseDirAsmPath))
{
return null;
logger.Log(PsesLogLevel.Diagnostic, $"Loading {args.Name} from PSES base dir into LoadFrom context");
return Assembly.LoadFrom(baseDirAsmPath);
}

// Then look in the shared .NET Standard directory
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");
return Assembly.LoadFrom(asmPath);
}

logger.Log(PsesLogLevel.Diagnostic, $"Loading {args.Name} from PSES dependency dir into LoadFrom context");
return Assembly.LoadFrom(asmPath);
return null;
};
#endif

Expand Down