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
Original file line number Diff line number Diff line change
Expand Up @@ -573,11 +573,19 @@ private void ImportModule_ViaAssembly(ImportModuleOptions importModuleOptions, A

if (!moduleLoaded)
{
bool found;
PSModuleInfo module = LoadBinaryModule(false, null, null, suppliedAssembly, null, null,
PSModuleInfo module = LoadBinaryModule(
trySnapInName: false,
moduleName: null,
fileName: null,
suppliedAssembly,
moduleBase: null,
ss: null,
importModuleOptions,
ManifestProcessingFlags.LoadElements | ManifestProcessingFlags.WriteErrors | ManifestProcessingFlags.NullOnFirstError,
this.BasePrefix, false /* loadTypes */ , false /* loadFormats */, out found);
this.BasePrefix,
loadTypes: false,
loadFormats: false,
out bool found);

if (found && module != null)
{
Expand Down
93 changes: 72 additions & 21 deletions src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -644,8 +644,8 @@ private bool ValidateManifestHash(
}

private PSModuleInfo LoadModuleNamedInManifest(PSModuleInfo parentModule, ModuleSpecification moduleSpecification, string moduleBase, bool searchModulePath,
string prefix, SessionState ss, ImportModuleOptions options, ManifestProcessingFlags manifestProcessingFlags, bool loadTypesFiles,
bool loadFormatFiles, object privateData, out bool found, string shortModuleName, PSLanguageMode? manifestLanguageMode)
string prefix, SessionState ss, ImportModuleOptions options, ManifestProcessingFlags manifestProcessingFlags, bool loadTypes,
bool loadFormats, object privateData, out bool found, string shortModuleName, PSLanguageMode? manifestLanguageMode)
{
PSModuleInfo module = null;
PSModuleInfo tempModuleInfoFromVerification = null;
Expand Down Expand Up @@ -878,19 +878,20 @@ private PSModuleInfo LoadModuleNamedInManifest(PSModuleInfo parentModule, Module
// At this point, we are already exhaust all possible ways to load the nested module. The last option is to load it as a binary module/snapin.
module = LoadBinaryModule(
parentModule,
true, // trySnapInName
trySnapInName: true,
moduleSpecification.Name,
null, // fileName
null, // assemblyToLoad
fileName: null,
assemblyToLoad: null,
moduleBase,
ss,
options,
manifestProcessingFlags,
prefix,
loadTypesFiles,
loadFormatFiles,
loadTypes,
loadFormats,
out found,
shortModuleName, false);
shortModuleName,
disableFormatUpdates: false);
}
catch (FileNotFoundException)
{
Expand Down Expand Up @@ -2927,8 +2928,8 @@ internal PSModuleInfo LoadModuleManifest(
ss: null,
options: nestedModuleOptions,
manifestProcessingFlags: manifestProcessingFlags,
loadTypesFiles: true,
loadFormatFiles: true,
loadTypes: true,
loadFormats: true,
privateData: privateData,
found: out found,
shortModuleName: null,
Expand Down Expand Up @@ -3030,8 +3031,8 @@ internal PSModuleInfo LoadModuleManifest(
ss: ss,
options: options,
manifestProcessingFlags: manifestProcessingFlags,
loadTypesFiles: (exportedTypeFiles == null || exportedTypeFiles.Count == 0), // If types files already loaded, don't load snapin files
loadFormatFiles: (exportedFormatFiles == null || exportedFormatFiles.Count == 0), // if format files already loaded, don't load snapin files
loadTypes: (exportedTypeFiles == null || exportedTypeFiles.Count == 0), // If types files already loaded, don't load snapin files
loadFormats: (exportedFormatFiles == null || exportedFormatFiles.Count == 0), // if format files already loaded, don't load snapin files
privateData: privateData,
found: out found,
shortModuleName: null,
Expand Down Expand Up @@ -5872,8 +5873,20 @@ internal PSModuleInfo LoadModule(PSModuleInfo parentModule, string fileName, str
ext.Equals(StringLiterals.PowerShellNgenAssemblyExtension, StringComparison.OrdinalIgnoreCase) ||
ext.Equals(StringLiterals.PowerShellILExecutableExtension, StringComparison.OrdinalIgnoreCase))
{
module = LoadBinaryModule(false, ModuleIntrinsics.GetModuleName(fileName), fileName, null,
moduleBase, ss, options, manifestProcessingFlags, prefix, true, true, out found);
module = LoadBinaryModule(
trySnapInName: false,
ModuleIntrinsics.GetModuleName(fileName),
fileName,
assemblyToLoad: null,
moduleBase,
ss,
options,
manifestProcessingFlags,
prefix,
loadTypes: true,
loadFormats: true,
out found);

if (found && module != null)
{
// LanguageMode does not apply to binary modules
Expand Down Expand Up @@ -6510,13 +6523,36 @@ private PSModuleInfo AnalyzeScriptFile(string filename, bool force, ExecutionCon
/// <param name="prefix">Command name prefix.</param>
/// <param name="found">Sets this to true if an assembly was found.</param>
/// <returns>THe module info object that was created...</returns>
internal PSModuleInfo LoadBinaryModule(bool trySnapInName, string moduleName, string fileName,
Assembly assemblyToLoad, string moduleBase, SessionState ss, ImportModuleOptions options,
ManifestProcessingFlags manifestProcessingFlags, string prefix,
bool loadTypes, bool loadFormats, out bool found)
internal PSModuleInfo LoadBinaryModule(
bool trySnapInName,
string moduleName,
string fileName,
Assembly assemblyToLoad,
string moduleBase,
SessionState ss,
ImportModuleOptions options,
ManifestProcessingFlags manifestProcessingFlags,
string prefix,
bool loadTypes,
bool loadFormats,
out bool found)
{
return LoadBinaryModule(null, trySnapInName, moduleName, fileName, assemblyToLoad, moduleBase, ss, options,
manifestProcessingFlags, prefix, loadTypes, loadFormats, out found, null, false);
return LoadBinaryModule(
parentModule: null,
trySnapInName,
moduleName,
fileName,
assemblyToLoad,
moduleBase,
ss,
options,
manifestProcessingFlags,
prefix,
loadTypes,
loadFormats,
out found,
shortModuleName: null,
disableFormatUpdates: false);
}

/// <summary>
Expand All @@ -6542,7 +6578,22 @@ internal PSModuleInfo LoadBinaryModule(bool trySnapInName, string moduleName, st
/// <param name="shortModuleName">Short name for module.</param>
/// <param name="disableFormatUpdates"></param>
/// <returns>THe module info object that was created...</returns>
internal PSModuleInfo LoadBinaryModule(PSModuleInfo parentModule, bool trySnapInName, string moduleName, string fileName, Assembly assemblyToLoad, string moduleBase, SessionState ss, ImportModuleOptions options, ManifestProcessingFlags manifestProcessingFlags, string prefix, bool loadTypes, bool loadFormats, out bool found, string shortModuleName, bool disableFormatUpdates)
internal PSModuleInfo LoadBinaryModule(
PSModuleInfo parentModule,
bool trySnapInName,
string moduleName,
string fileName,
Assembly assemblyToLoad,
string moduleBase,
SessionState ss,
ImportModuleOptions options,
ManifestProcessingFlags manifestProcessingFlags,
string prefix,
bool loadTypes,
bool loadFormats,
out bool found,
string shortModuleName,
bool disableFormatUpdates)
{
PSModuleInfo module = null;

Expand Down