Powershell: v7.0.0-preview.1: can't cast string to [WMIClass] anymore

Created on 31 May 2019  Â·  13Comments  Â·  Source: PowerShell/PowerShell

Steps to reproduce

Invoke the following:

[WMIClass] "\\$env:computerName\root\default:StdRegProv"

Expected behavior

Like in Windows PowerShell 5.1 and PowerShell 6.2.1, a ManagementClass object should be returned:

   NameSpace: ROOT\default
Name                                Methods              Properties
----                                -------              ----------
StdRegProv                          {CreateKey, DeleteK… {}

Actual behavior

Cannot convert value "\\SBAHOME\root\default:StdRegProv" to type "System.Management.ManagementClass". Error: "Cannot marshal 'parameter #3': Cannot marshal a string by-value with the [Out] attribute."
At line:1 char:1
+ [WMIClass] "\\$env:computerName\root\default:StdRegProv"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidArgument: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvalidCastToWMIClass

Environment data

PS C:/Users/steph> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.0.0-preview.1
PSEdition                      Core
GitCommitId                    7.0.0-preview.1
OS                             Microsoft Windows 10.0.18362
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
Issue-Bug Resolution-Fixed

Most helpful comment

they use that constructor in a finalizer.

Ooh, that's bad form!

All 13 comments

I can repo as:

[System.Management.ManagementClass]::new("test")

I guess it is .Net Core issue.
Tracking https://github.com/dotnet/corefx/issues/38093

@iSazonov what version of System.Management is PowerShell 7 referencing? If PowerShell updates the version of System.Management it ships with, then this exception should go away.

@SteveL-MSFT @daxian-dbw Should we close the issue or wait until we move to the new .Net preview version?

@iSazonov the System.Management DLL ships out of band (it’s not part of the SDK). It lives in its own NuGet package. You’re using an outdated version from before 3.0.0-preview3.

@jkoritzinsky Thanks for clarify!

Is https://www.nuget.org/packages/System.Management/4.6.0-preview5.19224.8 right version?

Yes that is the correct version.

Wouldn't Dependabot keep us up to date, or does that not automatically happen for major versions?

@SteveL-MSFT @daxian-dbw Do we ready to update all packages to new versions (from 4.5.* to 4.6.*)?

dependabot is configured to bump stable versions to newer stable versions, and pre-release versions to anything that is currently available. Since we have moved to target .NET Core 3.0 preview5, I think we should update the nuget references to the latest preview versions.

Ran into this as well. Importing the SCCM module hard crashes pwsh because they use that constructor in a finalizer.

they use that constructor in a finalizer.

Ooh, that's bad form!

:tada:This issue was addressed in #9888, which has now been successfully released as v7.0.0-preview.2.:tada:

Handy links:

Was this page helpful?
0 / 5 - 0 ratings