GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Import-Module does not work with .EXE binary modules · Issue #6741 · PowerShell/PowerShell

Import-Module does not work with .EXE binary modules #6741

New issue
Copy link
New issue
Copy link
Closed
Closed
Import-Module does not work with .EXE binary modules#6741
Copy link
Labels
Issue-BugIssue has been identified as a bug in the productIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.The issue is fixed.WG-Cmdletsgeneral cmdlet issuesgeneral cmdlet issues

Description

@kirillkovalenko
Kyrylo Kovalenko (kirillkovalenko)
opened on Apr 26, 2018
Issue body actions

PowerShell does not allow binary modules in form of an .EXE assembly file. We have a .NET .exe module that apart from other things contains a few powershell cmdlets. Sometimes I want to load this module into a standard PS host. Currently I cannot. I've tried 2 ways I'm aware of, and both do not work.

Is far as I know there are not technical reason that should prevent me from using .net .exe assembly as .dll assembly. If I rename the file to .dll it works.

Steps to reproduce

Way 1: Bare module file

Import-Module .\MyModule.exe

Way 2: Manifest file

@{ RootModule = 'MyModule.exe'; ModuleVersion = '2.0' }
Import-Module .\MyModule.psd1

Expected behavior

It works

Actual behavior

Way 1:

Import-Module : The extension '.exe' is not a valid module extension. The supported module extensions are '.dll', '.ps1', '.psm1', '.psd1', '.cdxml' and '.xaml'. Correct the extension then try adding the
file 'C:\Users\User\Workplace\Project1\Debug\MyModule.exe' again.
At line:1 char:1
+ Import-Module .\MyModule.exe
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (:) [Import-Module], InvalidOperationException
    + FullyQualifiedErrorId : Modules_InvalidModuleExtension,Microsoft.PowerShell.Commands.ImportModuleCommand

Ways 2:

Import-Module : Object reference not set to an instance of an object.
At line:1 char:1
+ Import-Module .\MyModule.psd1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Import-Module], NullReferenceException
    + FullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShell.Commands.ImportModuleCommand

The call stack:

Object reference not set to an instance of an object.
   at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModuleNamedInManifest(PSModuleInfo parentModule, ModuleSpecification moduleSpecification, String moduleBase, Boolean searchModulePath, String prefix, SessionState ss, ImportModuleOptions options, ManifestProcessingFlags manifestProcessingFlags, Boolean loadTypesFiles, Boolean loadFormatFiles, Object privateData, Boolean& found, String shortModuleName)
   at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModuleManifest(String moduleManifestPath, ExternalScriptInfo scriptInfo, Hashtable data, Hashtable localizedData, ManifestProcessingFlags manifestProcessingFlags, Version minimumVersion, Version maximumVersion, Version requiredVersion, Nullable`1 requiredModuleGuid, ImportModuleOptions& options, Boolean& containedErrors)
   at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModule(PSModuleInfo parentModule, String fileName, String moduleBase, String prefix, SessionState ss, Object privateData, ImportModuleOptions& options, ManifestProcessingFlags manifestProcessingFlags, Boolean& found, Boolean& moduleFileFound)
   at Microsoft.PowerShell.Commands.ImportModuleCommand.ImportModule_LocallyViaName(ImportModuleOptions importModuleOptions, String name)
   at Microsoft.PowerShell.Commands.ImportModuleCommand.ProcessRecord()
   at System.Management.Automation.Cmdlet.DoProcessRecord()
   at System.Management.Automation.CommandProcessor.ProcessRecord()

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.0.0
PSEdition                      Core
GitCommitId                    v6.0.0
OS                             Microsoft Windows 10.0.15063
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

  1. Bruce Payette (BrucePay)
    added
    Issue-BugIssue has been identified as a bug in the productIssue has been identified as a bug in the product
    WG-Cmdletsgeneral cmdlet issuesgeneral cmdlet issues
    on Apr 26, 2018
  2. BrucePay commented on Apr 26, 2018

    @BrucePay
    Bruce Payette (BrucePay)
    on Apr 26, 2018
    Collaborator
    More actions

    Does this module contain cmdlets? If not, then you should really use the AssembliesToProcess field. This will be faster since the module loader won't scan all the types in the assembly looking for cmdlets. Alternatively you can use Add-Type -AssemblyName ... to directly load the module. Hopefully these alternatives will unblock you.

    Otherwise, the null pointer exception is definitely a bug that should be fixed. Restricting the set of extensions allowed as RootModule was deliberated and I vaguely recall that we specifically chose to exclude executables but I can't remember why. Kenneth Hansen (@khansen00) - do you remember?

  3. kirillkovalenko commented on Apr 27, 2018

    @kirillkovalenko
    Kyrylo Kovalenko (kirillkovalenko)
    on Apr 27, 2018
    Author
    More actions

    Bruce Payette (@BrucePay) Yes, this module contains cmdlets. Below is a minimal module to reproduce this issue

    namespace Module6741
    {
        [Cmdlet(VerbsCommon.Get, "FooBar")]
        public class GetFooBarCmdlet : PSCmdlet
        {
            protected override void ProcessRecord()
            {
                WriteObject("FooBar");
            }
        }
    
        internal class EntryPoint
        {
            public static void Main(string[] args)
            {
            }
        }
    }
  4. kirillkovalenko commented on Apr 27, 2018

    @kirillkovalenko
    Kyrylo Kovalenko (kirillkovalenko)
    on Apr 27, 2018
    Author
    More actions

    Bruce Payette (@BrucePay) I see no AssembliesToProcess so I assume you meant RequiredAssemblies manifest field. If I add RequiredAssemblies instead of RootModule the import-module does not crash, but no cmdlets get exported either.

    > ipmo .\MyModule.psd1
    > Get-Module MyModule
    
    ModuleType Version    Name                                ExportedCommands
    ---------- -------    ----                                ----------------
    Manifest   1.0        MyModule
    
  5. kirillkovalenko commented on Apr 27, 2018

    @kirillkovalenko
    Kyrylo Kovalenko (kirillkovalenko)
    on Apr 27, 2018
    Author
    More actions

    Bruce Payette (@BrucePay) The Add-Type -AssemblyName didn't work for as well. Am I doing it wrong?

    > Add-Type -AssemblyName "ExeModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"
    > Get-FooBar
    Get-FooBar : The term 'Get-FooBar' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is
    correct and try again.
    
  6. SeeminglyScience commented on May 1, 2018

    @SeeminglyScience
    Patrick Meinecke (SeeminglyScience)
    on May 1, 2018
    Contributor
    More actions

    Kyrylo Kovalenko (@kirillkovalenko) Import-Module has an Assembly parameter that takes a System.Reflection.Assembly object. This works for me:

    $assembly = [System.Reflection.Assembly]::LoadFrom('Path\To\Module.exe')
    Import-Module -Assembly $assembly
    Reacted by Dan Thompson, Manuel and Jan Verhaeghe
    Reacted by Kyrylo Kovalenko
  7. Bruce Payette (BrucePay)
    added a commit that references this issue on Jul 12, 2018

    Fix for PowerShell#6741 Allow .exe files to be used as binary modules

    3bbad3f
  8. Steve Lee (SteveL-MSFT)
    added a commit that references this issue on Feb 5, 2019

    Fix for PowerShell#6741 Allow .exe files to be used as binary modules

    108f364
  9. Travis Plunk (TravisEz13)
    added a commit that references this issue on Feb 7, 2019

    Allow `.exe` files to be used as IL binary modules (#7281)

    6bc6257
  10. Ilya (iSazonov)
    added
    Resolution-FixedThe issue is fixed.The issue is fixed.
    on Feb 8, 2019
  11. Ilya (iSazonov)
    closed this as completedon Feb 8, 2019
  12. Thatgfsj (Thatgfsj)
    added a commit that references this issue on Aug 6, 2026

    Allow `.exe` files to be used as IL binary modules (PowerShell#7281)

    f045979
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIssue has been identified as a bug in the productIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.The issue is fixed.WG-Cmdletsgeneral cmdlet issuesgeneral cmdlet issues

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.