Repository navigation
Closed
Labels
Resolution-DuplicateThe issue is a duplicate.
Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
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 1Environment 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.0Visuals
Metadata
Metadata
Assignees
Labels
Resolution-DuplicateThe issue is a duplicate.

Activity
mklement0 commentedon Jan 25, 2023
It is
Import-Module AppXthat triggers your error, and the error suggests that in effectImport-Module AppX -SkipEditionCheckwas 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
-SkipEditionCheckvia$PSDefaultParamaterValues, as in the following example: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.Xehlwan commentedon Jan 26, 2023
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.0and up, including7.4.0-preview.1. In version7.0.13and lower, the commandImport-Module AppXworks as expected.In my testing,
$PSDefaultParameterValueshad no values set, and the commandImport-Module AppX -SkipEditionCheck:$falsealso failed.However running the command
Import-Module Appx -UseWindowsPowerShelldoes work as a workaround in all versions tested.mklement0 commentedon Jan 26, 2023
That is mysterious, given that
-UseWindowsPowerShellshould 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.
Xehlwan commentedon Jan 27, 2023
I just tried your suggestion, and you were right. For some reason the manifest does indeed list both
DesktopandCore. 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
Coreentry, 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.mklement0 commentedon Jan 27, 2023
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
Corecompatibility entry was ever there by design).Xehlwan commentedon Jan 27, 2023
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.mklement0 commentedon Jan 27, 2023
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
Appxmodule that is aware of the incompatibility (as is the case for me on my W11 22H2 release that comes withWindows PowerShell v5.1.22621.963).Xehlwan commentedon Jan 27, 2023
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.
SeeminglyScience commentedon Jan 27, 2023
Duplicate of #13138
SeeminglyScience commentedon Jan 27, 2023
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.
Modifyinc commentedon Mar 19, 2024
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.
Fix Windows 10 installation Appx commands error when pwsh.exe installed
Fix Windows 10 installation Appx commands error when pwsh.exe installed
BWWIT commentedon Dec 1, 2024
To modify the manifest of module Appx (you might have to do this in Powsershell Windows?):
On one PC in Powershell 7 I imported the module like this:
Fix issues on Windows 10
Fix issues on Windows 10
Fix issues on Windows 10