Skip to content
Closed
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
19 changes: 17 additions & 2 deletions src/PowerShellEditorServices.Hosting/EditorServicesLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,15 @@ public static EditorServicesLoader Create(

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

// Then look in the shared .NET Standard directory
string asmPath = Path.Combine(s_psesDependencyDirPath, dllName);
if (File.Exists(asmPath))
if (RequiredAssemblyExists(asmPath, asmName))
{
logger.Log(PsesLogLevel.Diagnostic, $"Loading {args.Name} from PSES dependency dir into LoadFile context");
return Assembly.LoadFile(asmPath);
Expand Down Expand Up @@ -394,5 +394,20 @@ private static object GetPSVersion()
.GetMethod("get_PSVersion", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)
.Invoke(null, new object[0] /* Cannot use Array.Empty, since it must work in net452 */);
}

private static bool RequiredAssemblyExists(string assemblyPath, AssemblyName requiredAssembly)
{
try
{
AssemblyName foundAsm = AssemblyName.GetAssemblyName(assemblyPath);
return foundAsm.Equals(requiredAssembly);
}
catch
{
// Do nothing
}

return false;
}
}
}