Title: Can't directly construct a generic list from a Boolean scalar · Issue #17731 · PowerShell/PowerShell · GitHub
Open Graph Title: Can't directly construct a generic list from a Boolean scalar · Issue #17731 · PowerShell/PowerShell
X Title: Can't directly construct a generic list from a Boolean scalar · Issue #17731 · PowerShell/PowerShell
Description: Steps to reproduce These statements return an error: [System.Collections.Generic.List[bool]]$False [System.Collections.Generic.List[bool]]$True [System.Collections.Generic.List[psobject]]$True [System.Collections.Generic.List[bool]]($Tru...
Open Graph Description: Steps to reproduce These statements return an error: [System.Collections.Generic.List[bool]]$False [System.Collections.Generic.List[bool]]$True [System.Collections.Generic.List[psobject]]$True [Sys...
X Description: Steps to reproduce These statements return an error: [System.Collections.Generic.List[bool]]$False [System.Collections.Generic.List[bool]]$True [System.Collections.Generic.List[psobject]]$True [Sys...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/17731
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Can't directly construct a generic list from a Boolean scalar","articleBody":"### Steps to reproduce\r\n\r\nThese statements return an error:\r\n\r\n```PowerShell\r\n[System.Collections.Generic.List[bool]]$False\r\n[System.Collections.Generic.List[bool]]$True\r\n[System.Collections.Generic.List[psobject]]$True\r\n[System.Collections.Generic.List[bool]]($True)\r\n\r\n$Bool = $True\r\n[System.Collections.Generic.List[bool]]$Bool\r\n```\r\n\r\nWhile these statements work fine:\r\n```PowerShell\r\n[System.Collections.Generic.List[int]]3\r\n[System.Collections.Generic.List[string]]'Test'\r\n[System.Collections.Generic.List[psobject]]'Test'\r\n[System.Collections.Generic.List[bool]]($True, $True)\r\n[Array]$True\r\n```\r\n\r\n### Expected behavior\r\nAll statements to return a generic list with a single (boolean) item without any error\r\n\r\n### Actual behavior\r\nStatements that have a single boolean as constructor parameter produce an error\r\n\r\n### Error details\r\n```\r\nInvalidArgument: Cannot convert value \"True\" to type \"System.Collections.Generic.List`1[System.Boolean]\". Error: \"Invalid cast from 'System.Boolean' to 'System.Collections.Generic.List`1[[System.Boolean, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]'.\"\r\n```\r\n\r\n### Workaround:\r\nUse the [Array subexpression operator `@( )`](https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_operators#array-subexpression-operator--):\r\n```PowerShell\r\n[System.Collections.Generic.List[bool]]@($True)\r\n$True\r\n```\r\n\r\n### Environment data\r\n\r\n```powershell\r\nName Value\r\n---- -----\r\nPSVersion 7.2.5\r\nPSEdition Core\r\nGitCommitId 7.2.5\r\nOS Microsoft Windows 10.0.22000\r\nPlatform Win32NT\r\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}\r\nPSRemotingProtocolVersion 2.3\r\nSerializationVersion 1.1.0.1\r\nWSManStackVersion 3.0\r\n```\r\n","author":{"url":"https://github.com/iRon7","@type":"Person","name":"iRon7"},"datePublished":"2022-07-20T17:51:35Z","url":"https://github.com/PowerShell/PowerShell/issues/17731"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:fba066b1-71dd-0741-2e01-e1a2825cd0a0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D814:364C19:2DF44D:406C8E:6AFD7557 |
| html-safe-nonce | 679f6b607b35af2ef407ecc38aaa36534e19d6c75a75121c68524928198498ed |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEODE0OjM2NEMxOToyREY0NEQ6NDA2QzhFOjZBRkQ3NTU3IiwidmlzaXRvcl9pZCI6IjQwNzA4NjczNTAzNzc1NTkzODMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 873e4e492114179a4dc6f13650abc1693c33ed18aceb29497326009ab5e134b7 |
| hovercard-subject-tag | issue:1311601121 |
| 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/17731/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2a72fe925efa6ff803620f8c991981b08c00f3d79298f3d343971b13d37211f8/PowerShell/PowerShell/issues/17731 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2a72fe925efa6ff803620f8c991981b08c00f3d79298f3d343971b13d37211f8/PowerShell/PowerShell/issues/17731 |
| og:image:alt | Steps to reproduce These statements return an error: [System.Collections.Generic.List[bool]]$False [System.Collections.Generic.List[bool]]$True [System.Collections.Generic.List[psobject]]$True [Sys... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | iRon7 |
| hostname | github.com |
| expected-hostname | github.com |
| None | e54006cf2b96d1ac260960edd10003132911469ccd1ec99c9803119fe2a4e032 |
| 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 | 5be0bf2b8cf26f8897d31e6bc3c232d328b12a54 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width