Title: Cannot convert value, Deserialized when running powershell from a pulished .net project · Issue #16525 · PowerShell/PowerShell · GitHub
Open Graph Title: Cannot convert value, Deserialized when running powershell from a pulished .net project · Issue #16525 · PowerShell/PowerShell
X Title: Cannot convert value, Deserialized when running powershell from a pulished .net project · Issue #16525 · PowerShell/PowerShell
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 reprodu...
Open Graph 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 PowerSh...
X 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 PowerSh...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/16525
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Cannot convert value, Deserialized when running powershell from a pulished .net project","articleBody":"### Prerequisites\n\n- [X] Write a descriptive title.\n- [X] Make sure you are able to repro it on the [latest released version](https://github.com/PowerShell/PowerShell/releases)\n- [X] Search the existing issues.\n- [X] Refer to the [FAQ](https://github.com/PowerShell/PowerShell/blob/master/docs/FAQ.md).\n- [X] Refer to [Differences between Windows PowerShell 5.1 and PowerShell](https://docs.microsoft.com/powershell/scripting/whats-new/differences-from-windows-powershell).\n\n### Steps to reproduce\n\nI am trying to open a remote WMI session in a powershell script I'm running from a .Net project (using System.Management.Automation.Powershell)\r\nWhen 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.\r\nI 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.\r\nI 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.\r\n\r\n`\r\n $SessionOption = New-CimSessionOption -Culture $Script:InvariantCulture -UICulture $Script:InvariantCulture -Protocol DCOM\r\n $sessionParameters = @{\r\n ComputerName = $ComputerAddress\r\n SessionOption = $DcomOptions\r\n Credential = $credentials\r\n }\r\n\r\n # Create session\r\n $session = New-CimSession @sessionParameters -ErrorAction SilentlyContinue`\r\n\r\nPublished using:\r\ndotnet 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\n\n### Expected behavior\n\n```console\n$session has a valid CimSession\r\n(it happens this way in some modes of running the script)\n```\n\n\n### Actual behavior\n\n```console\n$session is null error detailed bellow.\n```\n\n\n### Error details\n\n```console\nCannot 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\"\n```\n\n\n### Environment data\n\n```powershell\n$PSVersionTable.PSVersion 7.1.3\r\n.Net 5.0\n```\n\n\n### Visuals\n\n_No response_","author":{"url":"https://github.com/asaf-frieder","@type":"Person","name":"asaf-frieder"},"datePublished":"2021-11-28T12:23:56.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":11},"url":"https://github.com/16525/PowerShell/issues/16525"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:a0068dad-876e-8c6b-d3e0-36758cefb10e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A404:EB57A:DDEAC:128470:6A546600 |
| html-safe-nonce | 6f35099d3ca5bd32433ef5e3e23aa04771c4b7130de9de7501c5f6cdaf8ad51e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNDA0OkVCNTdBOkRERUFDOjEyODQ3MDo2QTU0NjYwMCIsInZpc2l0b3JfaWQiOiIyOTg4NzAzOTIwMTMyNzQ0NzA0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 5b7a322e2b6dd4bd7d6f6097f9cbb2944e4531a8cf479deb39e78f671b253408 |
| hovercard-subject-tag | issue:1065318255 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/16525/issue_layout |
| twitter:image | https://opengraph.githubassets.com/dcfffc54d68dc8f0ff15ddcb55006244ed4ccb4dd91c3ac35f79bf0a6a3eac4b/PowerShell/PowerShell/issues/16525 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/dcfffc54d68dc8f0ff15ddcb55006244ed4ccb4dd91c3ac35f79bf0a6a3eac4b/PowerShell/PowerShell/issues/16525 |
| og:image:alt | 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 PowerSh... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | asaf-frieder |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 6d28624802c2f7d9500239dd6870ed7031b7353b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width