Skip to content

Commit 47f6b18

Browse files
authored
Probe netfx dir for deps (#1151)
1 parent 327ffdf commit 47f6b18

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/PowerShellEditorServices.Hosting/EditorServicesLoader.cs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public sealed class EditorServicesLoader : IDisposable
2929
{
3030
private const int Net461Version = 394254;
3131

32+
#if !CoreCLR
33+
private static readonly string s_psesBaseDirPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
34+
#endif
35+
3236
private static readonly string s_psesDependencyDirPath = Path.GetFullPath(
3337
Path.Combine(
3438
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
@@ -72,7 +76,6 @@ public static EditorServicesLoader Create(
7276

7377
#if CoreCLR
7478
// In .NET Core, we add an event here to redirect dependency loading to the new AssemblyLoadContext we load PSES' dependencies into
75-
7679
logger.Log(PsesLogLevel.Verbose, "Adding AssemblyResolve event handler for new AssemblyLoadContext dependency loading");
7780

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

125128
var asmName = new AssemblyName(args.Name);
126-
string asmPath = Path.Combine(s_psesDependencyDirPath, $"{asmName.Name}.dll");
127-
if (!File.Exists(asmPath))
129+
var dllName = $"{asmName.Name}.dll";
130+
131+
// First look for the required assembly in the .NET Framework DLL dir
132+
string baseDirAsmPath = Path.Combine(s_psesBaseDirPath, dllName);
133+
if (File.Exists(baseDirAsmPath))
128134
{
129-
return null;
135+
logger.Log(PsesLogLevel.Diagnostic, $"Loading {args.Name} from PSES base dir into LoadFrom context");
136+
return Assembly.LoadFrom(baseDirAsmPath);
137+
}
138+
139+
// Then look in the shared .NET Standard directory
140+
string asmPath = Path.Combine(s_psesDependencyDirPath, dllName);
141+
if (File.Exists(asmPath))
142+
{
143+
logger.Log(PsesLogLevel.Diagnostic, $"Loading {args.Name} from PSES dependency dir into LoadFrom context");
144+
return Assembly.LoadFrom(asmPath);
130145
}
131146

132-
logger.Log(PsesLogLevel.Diagnostic, $"Loading {args.Name} from PSES dependency dir into LoadFrom context");
133-
return Assembly.LoadFrom(asmPath);
147+
return null;
134148
};
135149
#endif
136150

0 commit comments

Comments
 (0)