Skip to content

Add-AppPackage does not work on powershell 7 and gives the error: Operation is not supported on this platform. (0x80131539) #19031

Closed

Description

Prerequisites

Steps to reproduce

Add-AppPackage is not working on powershell 7 and gives the error: "Operation is not supported on this platform. (0x80131539)". The same command works on windows powershell.

Expected behavior

The Add-AppPackage to work

Actual behavior

Add-AppPackage does not work on powershell 7 and gives the error: Operation is not supported on this platform. (0x80131539)

Error details

Exception             :
    Type       : System.PlatformNotSupportedException
    TargetSite :
        Name          : GetExportedTypes
        DeclaringType : System.Reflection.RuntimeAssembly, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral,
PublicKeyToken=7cec85d7bea7798e
        MemberType    : Method
        Module        : System.Private.CoreLib.dll
    Message    : Operation is not supported on this platform. (0x80131539)
    Source     : System.Private.CoreLib
    HResult    : -2146233031
    StackTrace :
   at System.Reflection.RuntimeAssembly.GetExportedTypes()
   at System.Management.Automation.Runspaces.PSSnapInHelpers.GetAssemblyTypes(Assembly assembly, String name)
   at System.Management.Automation.Runspaces.PSSnapInHelpers.AnalyzeModuleAssemblyWithReflection(Assembly assembly,
String name, PSSnapInInfo psSnapInInfo, PSModuleInfo moduleInfo, String helpFile, Dictionary`2& cmdlets, Dictionary`2&
aliases, Dictionary`2& providers)
   at System.Management.Automation.Runspaces.PSSnapInHelpers.AnalyzePSSnapInAssembly(Assembly assembly, String name,
PSSnapInInfo psSnapInInfo, PSModuleInfo moduleInfo, Dictionary`2& cmdlets, Dictionary`2& aliases, Dictionary`2&
providers, String& helpFile)
   at System.Management.Automation.Runspaces.InitialSessionState.ImportCmdletsFromAssembly(Assembly assembly,
PSModuleInfo module)
   at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadBinaryModule(PSModuleInfo parentModule, String moduleName,
String fileName, Assembly assemblyToLoad, String moduleBase, SessionState ss, ImportModuleOptions options,
ManifestProcessingFlags manifestProcessingFlags, String prefix, Boolean& found, String shortModuleName, Boolean
disableFormatUpdates)
   at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModuleNamedInManifest(PSModuleInfo parentModule,
ModuleSpecification moduleSpecification, String moduleBase, Boolean searchModulePath, String prefix, SessionState ss,
ImportModuleOptions options, ManifestProcessingFlags manifestProcessingFlags, Object privateData, Boolean& found,
String shortModuleName, Nullable`1 manifestLanguageMode)
   at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModuleManifest(String moduleManifestPath, ExternalScriptInfo
manifestScriptInfo, 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.ModuleCmdletBase.LoadUsingExtensions(PSModuleInfo parentModule, String moduleName,
String fileBaseName, String extension, String moduleBase, String prefix, SessionState ss, ImportModuleOptions options,
ManifestProcessingFlags manifestProcessingFlags, Boolean& found, Boolean& moduleFileFound)
   at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadUsingModulePath(PSModuleInfo parentModule, IEnumerable`1
modulePath, String name, SessionState ss, ImportModuleOptions options, ManifestProcessingFlags
manifestProcessingFlags, PSModuleInfo& module)
   at Microsoft.PowerShell.Commands.ImportModuleCommand.ImportModule_LocallyViaName(ImportModuleOptions
importModuleOptions, String name)
   at Microsoft.PowerShell.Commands.ImportModuleCommand.ImportModule_LocallyViaName_WithTelemetry(ImportModuleOptions
importModuleOptions, String name)
   at Microsoft.PowerShell.Commands.ImportModuleCommand.ProcessRecord()
   at System.Management.Automation.CommandProcessor.ProcessRecord()
CategoryInfo          : NotSpecified: (:) [Import-Module], PlatformNotSupportedException
FullyQualifiedErrorId : System.PlatformNotSupportedException,Microsoft.PowerShell.Commands.ImportModuleCommand
InvocationInfo        :
    MyCommand        : Import-Module
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : 1
    Line             : Import-Module Appx
    PositionMessage  : At line:1 char:1
                       + Import-Module Appx
                       + ~~~~~~~~~~~~~~~~~~
    InvocationName   : Import-Module
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1

Environment data

Name                           Value
----                           -----
PSVersion                      7.3.2
PSEdition                      Core
GitCommitId                    7.3.2
OS                             Microsoft Windows 10.0.19045
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

image

Activity

  1. added
    Needs-Triage
    on Jan 25, 2023
  2. mklement0 commented on Jan 25, 2023

    @mklement0
    Contributor

    It is Import-Module AppX that triggers your error, and the error suggests that in effect Import-Module AppX -SkipEditionCheck was performed, i.e. an attempt to load this Windows PowerShell-only module into PowerShell Core, instead of the default behavior of using the Windows PowerShell Compatibility feature to load the module.

    The only explanation I can think of is that you've preset -SkipEditionCheck via $PSDefaultParamaterValues, as in the following example:

    $PSDefaultParameterValues['Import-Module:SkipEditionCheck'] = $true
    Import-Module AppX # predictably FAILS, because -SkipEditionCheck is now implicitly applied.

    If so, you can override the preset ad hoc with Import-Module AppX -SkipEditionCheck:$false, but the better solution is not to preset this switch to begin with.

  3. Xehlwan commented on Jan 26, 2023

    @Xehlwan

    I've made some testing, as a user, to find when the problem started occurring.
    To start with, I've found that this issue is present from version 7.1.0 and up, including 7.4.0-preview.1. In version 7.0.13 and lower, the command Import-Module AppX works as expected.

    In my testing, $PSDefaultParameterValues had no values set, and the command Import-Module AppX -SkipEditionCheck:$false also failed.

    However running the command Import-Module Appx -UseWindowsPowerShell does work as a workaround in all versions tested.

  4. mklement0 commented on Jan 26, 2023

    @mklement0
    Contributor

    That is mysterious, given that -UseWindowsPowerShell should be implied for any WinPS modules that aren't PS Core-compatible.

    I don't see the problem, neither in 7.3.2 nor in 7.4.0-preview.1

    The only other thing I can personally think of - and it seems unlikely - is that somehow the module manifest on your machine was modified to - incorrectly - signal PS Core compatibility.
    The expected output from the following command is Desktop (only):

    powershell { (Get-Module -ListAvailable Appx).CompatiblePSEditions }

    Other than that, I'm out of ideas, so hopefully others can shed light on this.

  5. Xehlwan commented on Jan 27, 2023

    @Xehlwan

    I just tried your suggestion, and you were right. For some reason the manifest does indeed list both Desktop and Core. I may be mistaken, but shouldn't this cause issues even in version 7.0.13 and earlier?

    In any case, I've found the exact same issue on two separate computers. On neither of these machines have I touched the manifest files. TrustedInstaller is still the owner of the files, and no other accounts have anything other than read permissions, so it seems unlikely that a 3rd party app has modified them.

    I tried taking control of the manifest and removing the Core entry, on one of my machines. As expected, everything works as it should after that. However, changing permissions for system files is not exactly an ideal solution, even if it works for me personally.

  6. mklement0 commented on Jan 27, 2023

    @mklement0
    Contributor

    Thanks for following up. Good to know the specific cause, though I have no explanation for what happened there.

    I would think that it would have caused issue in 7.0.13 and earlier too, though - at least hypothetically - removal of APIs in later underlying .NET versions could have introduced the problem later (assuming that a Core compatibility entry was ever there by design).

  7. Xehlwan commented on Jan 27, 2023

    @Xehlwan

    This is just a guess, but maybe the removal of built-in WinRT support in .Net 5 is related? Appx relies on WinRT classes, and apparently trying to activate a WinRT class is supposed to throw a PlatformNotSupportedException. And, from what I can see, version 7.1.0 is exactly when powershell moved to .Net 5.

  8. mklement0 commented on Jan 27, 2023

    @mklement0
    Contributor

    Great sleuthing.

    So the answer may be that you'll have to update to a more recent Windows version that comes with an updated Windows PowerShell including an updated Appx module that is aware of the incompatibility (as is the case for me on my W11 22H2 release that comes with Windows PowerShell v5.1.22621.963).

  9. Xehlwan commented on Jan 27, 2023

    @Xehlwan

    Unfortunately for anyone who can't upgrade to Win11, latest Win10, as of today, only has Windows Powershell v5.1.19041.2364. At least we found that there are workarounds. Hope that helps anyone else who runs into this issue.

    It would be nice if Powershell 7 could add support for WinRT, but I suppose that is more of a low-priority feature request.

  10. added
    Resolution-Duplicate
    and removed
    Needs-Triage
    on Jan 27, 2023
  11. SeeminglyScience commented on Jan 27, 2023

    @SeeminglyScience
    Contributor

    Duplicate of #13138

  12. SeeminglyScience commented on Jan 27, 2023

    @SeeminglyScience
    Contributor

    It would be nice if Powershell 7 could add support for WinRT, but I suppose that is more of a low-priority feature request.

    Unfortunately nothing we do would help with the AppX module specifically. The .NET runtime throws as soon as it reads the assembly reference to WinRT. There are some ways that WinRT could be supported, but that module would still need to be updated.

  13. ghost closed this as completedon Jan 28, 2023
  14. Modifyinc commented on Mar 19, 2024

    @Modifyinc

    I just tried your suggestion, and you were right. For some reason the manifest does indeed list both Desktop and Core. I may be mistaken, but shouldn't this cause issues even in version 7.0.13 and earlier?

    In any case, I've found the exact same issue on two separate computers. On neither of these machines have I touched the manifest files. TrustedInstaller is still the owner of the files, and no other accounts have anything other than read permissions, so it seems unlikely that a 3rd party app has modified them.

    I tried taking control of the manifest and removing the Core entry, on one of my machines. As expected, everything works as it should after that. However, changing permissions for system files is not exactly an ideal solution, even if it works for me personally.

    I'm having the same issue, showing Core and Desktop. Where is the manifest file so I can edit it as you did? I found a _manifest folder under the directory Program Files\PowerShell\7, but still not seeing it. I'm using W10 latest version.

  15. BWWIT commented on Dec 1, 2024

    @BWWIT

    I'm having the same issue, showing Core and Desktop. Where is the manifest file so I can edit it as you did? I found a _manifest folder under the directory Program Files\PowerShell\7, but still not seeing it. I'm using W10 latest version.

    To modify the manifest of module Appx (you might have to do this in Powsershell Windows?):

    $path = (Get-Module -ListAvailable Appx).path  # Get manifest-path
    cmd /c "icacls `"$path`" /grant:r %username%:(M)" # Set write-permission
    Update-ModuleManifest -Path ((Get-Module -ListAvailable Appx).path) -CompatiblePSEditions "Desktop" # Modify manifest
    cmd /c "icacls `"$path`" /remove %username%" # Remove write-permission

    On one PC in Powershell 7 I imported the module like this:

    Get-Module -ListAvailable -All Appx
    Import-module -Name Appx -UseWindowsPowerShell #
    # or this one, not sure what the difference is
    Import-module -Name Appx -SkipEditionCheck
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

    Resolution-Duplicate

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions