Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Cannot convert value, Deserialized when running powershell from a pulished .net project #16525

Copy link
Copy link
@asaf-frieder

Description

@asaf-frieder
Issue body actions

Prerequisites

Steps to reproduce

I am trying to open a remote WMI session in a powershell script I'm running from a .Net project (using System.Management.Automation.Powershell)
When running the script in powershell command line, or running the .net project directly from the visual studio the script works, however when publishing the .net project and running the published version it fails.
I receive the error while attempting to bind a parameter to the New-CimSession cmdlet generated by the New-CimSessionOption cmdlet. The New-CimSessionOption generates an object of type DComSessionOptions which is inherits the expected CimSessionOptions however it seems that it got deserialized (lost fidelity) and therefore the parameter failed to bind.
I have made several attempts to fix this using casting as well as create the dcom options my self and pass it explicitly as DComSessionOptions. In all cases attempting to run New-CimSession fails on the same error.

`
$SessionOption = New-CimSessionOption -Culture $Script:InvariantCulture -UICulture $Script:InvariantCulture -Protocol DCOM
$sessionParameters = @{
ComputerName = $ComputerAddress
SessionOption = $DcomOptions
Credential = $credentials
}

    # Create session
    $session = New-CimSession @sessionParameters -ErrorAction SilentlyContinue`

Published using:
dotnet publish C:\repos\WMI\WMITester\WMITester.csproj -c Release -r win7-x64 -o .\publish\WMITester\win\Release\x64 /p:PublishSingleFile=True /p:IncludeNativeLibrariesForSelfExtract=true /p:IncludeAllContentForSelfExtract=true /p:SelfContained=true /p:BuildNumber=8

Expected behavior

$session has a valid CimSession
(it happens this way in some modes of running the script)

Actual behavior

$session is null error detailed bellow.

Error details

Cannot bind parameter 'SessionOption'. Cannot convert value "Microsoft.Management.Infrastructure.Options.DComSessionOptions" to type "Microsoft.Management.Infrastructure.Options.CimSessionOptions". Error: "Cannot convert the "Microsoft.Management.Infrastructure.Options.DComSessionOptions" value of type "Deserialized.Microsoft.Management.Infrastructure.Options.DComSessionOptions" to type "Microsoft.Management.Infrastructure.Options.CimSessionOptions"

Environment data

$PSVersionTable.PSVersion 7.1.3
.Net 5.0

Visuals

No response

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-AnsweredThe question is answered.The question is answered.WG-DevEx-SDKhosting PowerShell as a runtime, PowerShell's APIs, PowerShell Standard, or development of moduleshosting PowerShell as a runtime, PowerShell's APIs, PowerShell Standard, or development of modules

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.