Try Assembly.Load correctly
This should resolve #791. Instead of checking if `Assembly.Load` returned null (it doesn't), check if it threw `FileNotFoundException`, which it will if it doesn't find the assembly.
This commit is contained in:
parent
80b15f64e2
commit
839014b599
1 changed files with 12 additions and 7 deletions
|
@ -186,10 +186,12 @@ namespace System.Management.Automation
|
||||||
|
|
||||||
// Try loading it from the TPA list. All PowerShell dependencies are in the
|
// Try loading it from the TPA list. All PowerShell dependencies are in the
|
||||||
// TPA list when published with dotnet-cli.
|
// TPA list when published with dotnet-cli.
|
||||||
asmLoaded = Assembly.Load(assemblyName);
|
try
|
||||||
|
{
|
||||||
|
asmLoaded = Assembly.Load(assemblyName);
|
||||||
|
}
|
||||||
// If it wasn't there, try loading from path
|
// If it wasn't there, try loading from path
|
||||||
if (asmLoaded == null)
|
catch (FileNotFoundException)
|
||||||
{
|
{
|
||||||
asmLoaded = asmFilePath.EndsWith(".ni.dll", StringComparison.OrdinalIgnoreCase)
|
asmLoaded = asmFilePath.EndsWith(".ni.dll", StringComparison.OrdinalIgnoreCase)
|
||||||
? LoadFromNativeImagePath(asmFilePath, null)
|
? LoadFromNativeImagePath(asmFilePath, null)
|
||||||
|
@ -250,9 +252,12 @@ namespace System.Management.Automation
|
||||||
|
|
||||||
// Try loading it from the TPA list. All PowerShell dependencies are in the
|
// Try loading it from the TPA list. All PowerShell dependencies are in the
|
||||||
// TPA list when published with dotnet-cli.
|
// TPA list when published with dotnet-cli.
|
||||||
asmLoaded = Assembly.Load(assemblyName);
|
try
|
||||||
|
{
|
||||||
if (asmLoaded == null)
|
asmLoaded = Assembly.Load(assemblyName);
|
||||||
|
}
|
||||||
|
// If it wasn't there, try loading from path
|
||||||
|
catch (FileNotFoundException)
|
||||||
{
|
{
|
||||||
// Load the assembly through 'LoadFromNativeImagePath' or 'LoadFromAssemblyPath'
|
// Load the assembly through 'LoadFromNativeImagePath' or 'LoadFromAssemblyPath'
|
||||||
asmLoaded = assemblyPath.EndsWith(".ni.dll", StringComparison.OrdinalIgnoreCase)
|
asmLoaded = assemblyPath.EndsWith(".ni.dll", StringComparison.OrdinalIgnoreCase)
|
||||||
|
@ -520,4 +525,4 @@ namespace System.Management.Automation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue