Skip to content
Merged
Show file tree
Hide file tree
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
130 changes: 65 additions & 65 deletions src/System.Management.Automation/engine/ExecutionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1322,71 +1322,71 @@ internal void RemoveAssembly(string name)
[SuppressMessage("Microsoft.Reliability", "CA2001:AvoidCallingProblematicMethods", MessageId = "System.Reflection.Assembly.LoadFrom")]
internal static Assembly LoadAssembly(string name, string filename, out Exception error)
{
// First we try to load the assembly based on the filename
Assembly loadedAssembly = null;
error = null;
if (!String.IsNullOrEmpty(filename))
{
try
{
loadedAssembly = Assembly.LoadFrom(filename);
}
catch (FileNotFoundException fileNotFound)
{
error = fileNotFound;
}
catch (FileLoadException fileLoadException)
{
error = fileLoadException;
}
catch (BadImageFormatException badImage)
{
error = badImage;
}
catch (SecurityException securityException)
{
error = securityException;
}
}
else if (!String.IsNullOrEmpty(name))
{
string fixedName = null;
// Remove the '.dll' if it's there...
fixedName = name.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)
? Path.GetFileNameWithoutExtension(name)
: name;
var assemblyString = Utils.IsPowerShellAssembly(fixedName)
? Utils.GetPowerShellAssemblyStrongName(fixedName)
: fixedName;
try
{
loadedAssembly = Assembly.Load(new AssemblyName(assemblyString));
}
catch (FileNotFoundException fileNotFound)
{
error = fileNotFound;
}
catch (FileLoadException fileLoadException)
{
error = fileLoadException;
// this is a legitimate error on CoreCLR for a newly emited with Add-Type assemblies
// they cannot be loaded by name, but we are only interested in importing them by path
}
catch (BadImageFormatException badImage)
{
error = badImage;
}
catch (SecurityException securityException)
{
error = securityException;
}
}
// We either return the loaded Assembly, or return null.
// First we try to load the assembly based on the filename

Assembly loadedAssembly = null;
error = null;

if (!String.IsNullOrEmpty(filename))
{
try
{
loadedAssembly = Assembly.LoadFrom(filename);
}
catch (FileNotFoundException fileNotFound)
{
error = fileNotFound;
}
catch (FileLoadException fileLoadException)
{
error = fileLoadException;
}
catch (BadImageFormatException badImage)
{
error = badImage;
}
catch (SecurityException securityException)
{
error = securityException;
}
}
else if (!String.IsNullOrEmpty(name))
{
string fixedName = null;
// Remove the '.dll' if it's there...
fixedName = name.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)
? Path.GetFileNameWithoutExtension(name)
: name;

var assemblyString = Utils.IsPowerShellAssembly(fixedName)
? Utils.GetPowerShellAssemblyStrongName(fixedName)
: fixedName;

try
{
loadedAssembly = Assembly.Load(new AssemblyName(assemblyString));
}
catch (FileNotFoundException fileNotFound)
{
error = fileNotFound;
}
catch (FileLoadException fileLoadException)
{
error = fileLoadException;
// this is a legitimate error on CoreCLR for a newly emited with Add-Type assemblies
// they cannot be loaded by name, but we are only interested in importing them by path
}
catch (BadImageFormatException badImage)
{
error = badImage;
}
catch (SecurityException securityException)
{
error = securityException;
}
}

// We either return the loaded Assembly, or return null.
return loadedAssembly;
}

Expand Down
Loading