Title: Calling base class method in a System.Xml.XmlNode-derived custom class fails; invokes own method instead, resulting in infinite recursion · Issue #6386 · PowerShell/PowerShell · GitHub
Open Graph Title: Calling base class method in a System.Xml.XmlNode-derived custom class fails; invokes own method instead, resulting in infinite recursion · Issue #6386 · PowerShell/PowerShell
X Title: Calling base class method in a System.Xml.XmlNode-derived custom class fails; invokes own method instead, resulting in infinite recursion · Issue #6386 · PowerShell/PowerShell
Description: The documented syntax for invoking a base-class method from a PS custom class is ([
Open Graph Description: The documented syntax for invoking a base-class method from a PS custom class is ([
X Description: The documented syntax for invoking a base-class method from a PS custom class is ([<base-class>] $this).<method>(), but that doesn't seem to work, as discovered in this SO question....
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/6386
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Calling base class method in a System.Xml.XmlNode-derived custom class fails; invokes own method instead, resulting in infinite recursion","articleBody":"The documented syntax for invoking a base-class method from a PS custom class is \r\n`([\u003cbase-class\u003e] $this).\u003cmethod\u003e()`, but that doesn't seem to work, as discovered in [this SO question](https://stackoverflow.com/q/49259408/45375).\r\n\r\nInstead, the derived class' method itself is invoked, resulting in infinite recursion.\r\n\r\n**Update**: The problem appears to be specific to `[System.Xml.XmlNode]`-derived classes; see [@daxian-dbw's comment below](https://github.com/PowerShell/PowerShell/issues/6386#issuecomment-372869624).\r\n\r\nA reflection-based workaround can be found in [this answer](https://stackoverflow.com/a/49265123/45375).\r\n\r\nSteps to reproduce\r\n------------------\r\n\r\n```powershell\r\nclass child : System.Xml.XmlDocument {\r\n [void] LoadXml([string]$content) {\r\n Write-Host 'Inside overridden LoadXml.'\r\n # Try to call the base type's .LoadXml() method.\r\n ([System.Xml.XmlDocument] $this).LoadXml($content)\r\n }\r\n}\r\n\r\n[child]::new().LoadXml('\u003cfoo\u003ebar\u003c/foo\u003e')\r\n```\r\n\r\nExpected behavior\r\n-----------------\r\n\r\n```none\r\nInside overridden LoadXml.\r\n```\r\n\r\nThe message should print once, and the XML string should be loaded into the instance via the call to the base-class method.\r\n\r\nActual behavior\r\n---------------\r\n\r\n```none\r\nInside overridden LoadXml.\r\nInside overridden LoadXml.\r\n...\r\n```\r\n\r\nThe method keeps calling itself and eventually runs into a call-depth overflow.\r\n\r\n\r\nEnvironment data\r\n----------------\r\n\r\n\u003c!-- provide the output of $PSVersionTable --\u003e\r\n\r\n```powershell\r\nPowerShell Core v6.0.1 on macOS 10.13.3\r\nPowerShell Core v6.0.1 on Ubuntu 16.04.3 LTS\r\nPowerShell Core v6.0.1 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)\r\nWindows PowerShell v5.1.15063.674 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)\r\n```\r\n","author":{"url":"https://github.com/mklement0","@type":"Person","name":"mklement0"},"datePublished":"2018-03-13T20:32:33.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/6386/PowerShell/issues/6386"}
| 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:84379f1d-5a3d-78bd-b1f6-4cf8070f63be |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9E62:46803:87F91D:C4CCFA:6A58C7FB |
| html-safe-nonce | bf72b97ce2397c6ad2b51c2b19d9fdeb2c1612d372346913a9a330e05db79df2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RTYyOjQ2ODAzOjg3RjkxRDpDNENDRkE6NkE1OEM3RkIiLCJ2aXNpdG9yX2lkIjoiMTc0MjI3ODExMTYyNzAzODY3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 18f93182641e15f75c32bcd90f185298c447f828e68530ba8dfc32582ef3b59c |
| hovercard-subject-tag | issue:304924876 |
| 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/6386/issue_layout |
| twitter:image | https://opengraph.githubassets.com/05906962afaad6b853651695282230a580662c91e2c110563fe7adb3f7234c34/PowerShell/PowerShell/issues/6386 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/05906962afaad6b853651695282230a580662c91e2c110563fe7adb3f7234c34/PowerShell/PowerShell/issues/6386 |
| og:image:alt | The documented syntax for invoking a base-class method from a PS custom class is ([ |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mklement0 |
| 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