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
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,8 @@ protected override Assembly Load(AssemblyName assemblyName)
string asmCultureName = assemblyName.CultureName ?? string.Empty;
string asmFilePath = null;

for (int i = 0; i < probingPaths.Count; i++)
foreach (var probingPath in probingPaths)
{
string probingPath = probingPaths[i];
string asmCulturePath = Path.Combine(probingPath, asmCultureName);
for (int k = 0; k < extensions.Length; k++)
{
Expand Down Expand Up @@ -184,19 +183,21 @@ protected override Assembly Load(AssemblyName assemblyName)
assemblyName.FullName);
}

// Try loading it from the TPA list. All PowerShell dependencies are in the
// TPA list when published with dotnet-cli.
try
{
asmLoaded = Assembly.Load(assemblyName);
}
// If it wasn't there, try loading from path
catch (FileNotFoundException)
{
asmLoaded = asmFilePath.EndsWith(".ni.dll", StringComparison.OrdinalIgnoreCase)
? LoadFromNativeImagePath(asmFilePath, null)
: LoadFromAssemblyPath(asmFilePath);
}
// Since .NET CLI built versions of PowerShell have all the
// built-in assemblies in the TPA list, the above will throw,
// and we have to use Assembly.Load. However, we must try the
// above first, otherwise assemblies that exist outside the TPA
// list will go into a recursive loop.
catch (System.IO.FileLoadException)
{
asmLoaded = System.Reflection.Assembly.Load(assemblyName);
}

// If it loaded, add it to the cache
if (asmLoaded != null)
Expand Down Expand Up @@ -250,20 +251,22 @@ internal Assembly LoadFrom(string assemblyPath)
if (TryGetAssemblyFromCache(assemblyName, out asmLoaded))
return asmLoaded;

// Try loading it from the TPA list. All PowerShell dependencies are in the
// TPA list when published with dotnet-cli.
try
{
asmLoaded = Assembly.Load(assemblyName);
}
// If it wasn't there, try loading from path
catch (FileNotFoundException)
{
// Load the assembly through 'LoadFromNativeImagePath' or 'LoadFromAssemblyPath'
asmLoaded = assemblyPath.EndsWith(".ni.dll", StringComparison.OrdinalIgnoreCase)
? LoadFromNativeImagePath(assemblyPath, null)
: LoadFromAssemblyPath(assemblyPath);
}
// Since .NET CLI built versions of PowerShell have all the
// built-in assemblies in the TPA list, the above will throw,
// and we have to use Assembly.Load. However, we must try the
// above first, otherwise assemblies that exist outside the TPA
// list will go into a recursive loop.
catch (System.IO.FileLoadException)
{
asmLoaded = System.Reflection.Assembly.Load(assemblyName);
}

if (asmLoaded != null)
{
Expand Down Expand Up @@ -503,11 +506,11 @@ public class PowerShellAssemblyLoadContextInitializer

// Porting note: it's much easier to send an LPStr on Linux
private const UnmanagedType stringType =
#if LINUX
#if LINUX
UnmanagedType.LPStr
#else
#else
UnmanagedType.LPWStr
#endif
#endif
;

/// <summary>
Expand Down