Title: CodeMethod invoke fails with dot syntax but works with Foreach-Object -MemberName · Issue #4826 · PowerShell/PowerShell · GitHub
Open Graph Title: CodeMethod invoke fails with dot syntax but works with Foreach-Object -MemberName · Issue #4826 · PowerShell/PowerShell
X Title: CodeMethod invoke fails with dot syntax but works with Foreach-Object -MemberName · Issue #4826 · PowerShell/PowerShell
Description: Steps to reproduce using namespace System.Management.Automation class Y{ [int] $Id } class X{ static [void] OpenUri([psobject] $obj) { $id = $obj.Id start-process "http://baseuri/$id" } static [void] UpdateTypeData(){ $td = [Runspaces.Ty...
Open Graph Description: Steps to reproduce using namespace System.Management.Automation class Y{ [int] $Id } class X{ static [void] OpenUri([psobject] $obj) { $id = $obj.Id start-process "http://baseuri/$id" } static [voi...
X Description: Steps to reproduce using namespace System.Management.Automation class Y{ [int] $Id } class X{ static [void] OpenUri([psobject] $obj) { $id = $obj.Id start-process "http://baseuri/$id" } s...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/4826
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"CodeMethod invoke fails with dot syntax but works with Foreach-Object -MemberName","articleBody":"\u003c!--\r\n\r\nIf it is a bug report:\r\n- make sure you are able to repro it on the latest released version. \r\nYou can install the latest version from https://github.com/PowerShell/PowerShell/releases\r\n- Search the existing issues.\r\n- Refer to the [FAQ](https://github.com/PowerShell/PowerShell/blob/master/docs/FAQ.md).\r\n- Refer to the [known issues](https://github.com/PowerShell/PowerShell/blob/master/docs/KNOWNISSUES.md).\r\n- Fill out the following repro template\r\n\r\nIf it's not a bug, please remove the template and elaborate the issue in your own words.\r\n--\u003e\r\n\r\nSteps to reproduce\r\n------------------\r\n\r\n```powershell\r\nusing namespace System.Management.Automation\r\nclass Y{\r\n [int] $Id\r\n}\r\n\r\nclass X{ \r\n\tstatic [void] OpenUri([psobject] $obj) {\r\n\t\t$id = $obj.Id\r\n\t\tstart-process \"http://baseuri/$id\"\r\n\t}\r\n\r\n static [void] UpdateTypeData(){\r\n $td = [Runspaces.Typedata]::new([Y])\t\t\r\n\t\t$td.Members.Add(\"OpenUri\",\r\n\t\t\t[Runspaces.CodeMethodData]::new(\"OpenUri\", [X]::GetMethodInfo([X], \"OpenUri\")));\r\n\t\tUpdate-TypeData -TypeData $td -Force\r\n }\r\n \r\n hidden static [Reflection.MethodInfo] GetMethodInfo([Type] $type, [string] $method) {\r\n\t\treturn $type.GetMethod($method, [Reflection.BindingFlags]::Static -bor [Reflection.BindingFlags]::Public -bor [Reflection.BindingFlags]::IgnoreCase);\r\n\t}\r\n}\r\n[X]::UpdateTypeData()\r\n\r\n$y = [Y]::new()\r\n\r\n#works\r\n$y | % OpenUri\r\n#fails with No coercion operator is defined between types 'System.Void' and 'System.Object'.\r\n$y.OpenUri()\r\n\r\n```\r\n\r\nExpected behavior\r\n-----------------\r\nSame behavior invoking method with dot syntax as when invoked via `Foreach-Object -MemberName`\r\n\r\nActual behavior\r\n---------------\r\nfails with\r\n```\r\nNo coercion operator is defined between types 'System.Void' and 'System.Object'.\r\nAt line:1 char:1\r\n+ $y.OpenUri()\r\n```\r\n```\r\nPS C:\\Program Files\\PowerShell\\6.0.0-beta.6\u003e $y | gm\r\n\r\n TypeName: Y\r\n\r\nName MemberType Definition\r\n---- ---------- ----------\r\nOpenUri CodeMethod static void OpenUri(psobject obj)\r\n```\r\n\r\nEnvironment data\r\n----------------\r\nAll versions (beta 6 and win 5.1)\r\n","author":{"url":"https://github.com/powercode","@type":"Person","name":"powercode"},"datePublished":"2017-09-13T10:16:57.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/4826/PowerShell/issues/4826"}
| 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:fc76cce0-1529-236b-4308-dfd2f884dd18 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8248:1756EF:5C12C5:808C87:6A586FB6 |
| html-safe-nonce | 4e411ea777310371cdc33571649e11d664222485fa3e27ca7686fe80da55cc93 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MjQ4OjE3NTZFRjo1QzEyQzU6ODA4Qzg3OjZBNTg2RkI2IiwidmlzaXRvcl9pZCI6IjMzMDIxNjE2MDI3NDE1NjMzMTgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 7f5bc27bc8f945c2627c601f2cf69fc47d1d489769dc3787396ee8b3164f99bb |
| hovercard-subject-tag | issue:257328768 |
| 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/4826/issue_layout |
| twitter:image | https://opengraph.githubassets.com/62a3447f132fb70f8c5fc0df4cc083320d5f761bdd4a2b7edfb83d3209f0e593/PowerShell/PowerShell/issues/4826 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/62a3447f132fb70f8c5fc0df4cc083320d5f761bdd4a2b7edfb83d3209f0e593/PowerShell/PowerShell/issues/4826 |
| og:image:alt | Steps to reproduce using namespace System.Management.Automation class Y{ [int] $Id } class X{ static [void] OpenUri([psobject] $obj) { $id = $obj.Id start-process "http://baseuri/$id" } static [voi... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | powercode |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f2a0c7865178af3d91dd9f13b0cdfc3c73a2529c873d2780bb4c01271a57ec6 |
| 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 | 8aae7b8d6caacacf5c66eaeb2702d8dc88d85b4a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width