Fix spurious error generated when importing cmdlets from an in-memory assembly (#4117)
This commit is contained in:
parent
3e35fb9918
commit
ece27ff687
|
@ -4494,10 +4494,14 @@ namespace System.Management.Automation.Runspaces
|
|||
string throwAwayHelpFile = null;
|
||||
PSSnapInHelpers.AnalyzePSSnapInAssembly(assembly, assemblyPath, null, module, true, out cmdlets, out aliases, out providers, out throwAwayHelpFile);
|
||||
|
||||
// If this is an in-memory assembly, don't added it to the list of AssemblyEntries
|
||||
// since it can't be loaded by path or name
|
||||
if (! string.IsNullOrEmpty(assembly.Location))
|
||||
{
|
||||
SessionStateAssemblyEntry assemblyEntry =
|
||||
new SessionStateAssemblyEntry(assembly.FullName, assemblyPath);
|
||||
|
||||
this.Assemblies.Add(assemblyEntry);
|
||||
}
|
||||
|
||||
if (cmdlets != null)
|
||||
{
|
||||
|
|
|
@ -6843,6 +6843,15 @@ namespace Microsoft.PowerShell.Commands
|
|||
|
||||
assemblyVersion = GetAssemblyVersionNumber(assemblyToLoad);
|
||||
assembly = assemblyToLoad;
|
||||
// If this is an in-memory only assembly, add it directly to the assembly cache if
|
||||
// it isn't already there.
|
||||
if (string.IsNullOrEmpty(assembly.Location))
|
||||
{
|
||||
if (! Context.AssemblyCache.ContainsKey(assembly.FullName))
|
||||
{
|
||||
Context.AssemblyCache.Add(assembly.FullName, assembly);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -7196,7 +7205,6 @@ namespace Microsoft.PowerShell.Commands
|
|||
{
|
||||
AddModuleToModuleTables(this.Context, this.TargetSessionState.Internal, module);
|
||||
}
|
||||
|
||||
return module;
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ Describe 'Argument transformation attribute on optional argument with explicit $
|
|||
'@
|
||||
$mod = Add-Type -PassThru -TypeDefinition $tdefinition
|
||||
|
||||
Import-Module $mod[0].Assembly
|
||||
Import-Module $mod[0].Assembly -ErrorVariable ErrorImportingModule
|
||||
|
||||
function Invoke-ScriptFunctionTakesObject
|
||||
{
|
||||
|
@ -68,6 +68,10 @@ Describe 'Argument transformation attribute on optional argument with explicit $
|
|||
}
|
||||
|
||||
|
||||
It "There was no error importing the in-memory module" {
|
||||
$ErrorImportingModule | Should Be $null
|
||||
}
|
||||
|
||||
It "Script function takes object" {
|
||||
Invoke-ScriptFunctionTakesObject | Should Be 42
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue