Title: PSCredential.Empty.GetNetworkCredential() throws NRE instead of returning null per docs · Issue #4696 · PowerShell/PowerShell · GitHub
Open Graph Title: PSCredential.Empty.GetNetworkCredential() throws NRE instead of returning null per docs · Issue #4696 · PowerShell/PowerShell
X Title: PSCredential.Empty.GetNetworkCredential() throws NRE instead of returning null per docs · Issue #4696 · PowerShell/PowerShell
Description: Steps to reproduce > [pscredential]::Empty.GetNetworkCredential() Expected behavior $null Per the docs, an "uninitialized" PSCredential object should return null MSDN also documents it as such, though only on the page of the explicit cas...
Open Graph Description: Steps to reproduce > [pscredential]::Empty.GetNetworkCredential() Expected behavior $null Per the docs, an "uninitialized" PSCredential object should return null MSDN also documents it as such, tho...
X Description: Steps to reproduce > [pscredential]::Empty.GetNetworkCredential() Expected behavior $null Per the docs, an "uninitialized" PSCredential object should return null MSDN also documents it...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/4696
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"PSCredential.Empty.GetNetworkCredential() throws NRE instead of returning null per docs","articleBody":"Steps to reproduce\r\n------------------\r\n\r\n```powershell\r\n\u003e [pscredential]::Empty.GetNetworkCredential()\r\n```\r\n\r\nExpected behavior\r\n-----------------\r\n\r\n```none\r\n$null\r\n```\r\n\r\nPer [the docs](https://github.com/PowerShell/PowerShell/blob/fd047a82506ac6a38c20052f45683cf5407c9c3a/src/System.Management.Automation/engine/Credential.cs#L248), an \"uninitialized\" `PSCredential` object should return `null`\r\n\r\nMSDN also documents it as such, though only on [the page of the explicit cast operator](https://msdn.microsoft.com/en-us/library/system.management.automation.pscredential.op_explicit) which just calls `GetNetworkCredential`\r\n\r\nActual behavior\r\n---------------\r\n\r\n```none\r\nException calling \"GetNetworkCredential\" with \"0\" argument(s): \"Object reference not set to an instance of an object.\"\r\nAt line:1 char:1\r\n+ [pscredential]::Empty.GetNetworkCredential()\r\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n + CategoryInfo : NotSpecified: (:) [], MethodInvocationException\r\n + FullyQualifiedErrorId : NullReferenceException\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\n\u003e $PSVersionTable\r\n\r\nName Value\r\n---- -----\r\nPSVersion 5.0.10586.117\r\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}\r\nBuildVersion 10.0.10586.117\r\nCLRVersion 4.0.30319.42000\r\nWSManStackVersion 3.0\r\nPSRemotingProtocolVersion 2.3\r\nSerializationVersion 1.1.0.1\r\n```\r\n\r\n---\r\n\r\n[`_userName` is `null`](https://github.com/PowerShell/PowerShell/blob/fd047a82506ac6a38c20052f45683cf5407c9c3a/src/System.Management.Automation/engine/Credential.cs#L266) so [`SplitUserDomain` throws at the `IndexOf()`](https://github.com/PowerShell/PowerShell/blob/fd047a82506ac6a38c20052f45683cf5407c9c3a/src/System.Management.Automation/engine/Credential.cs#L369)\r\n\r\n```\r\n\u003e $Error[0].Exception.InnerException.StackTrace\r\n\r\n at System.Management.Automation.PSCredential.SplitUserDomain(String input, String\u0026 user, String\u0026 domain)\r\n at System.Management.Automation.PSCredential.IsValidUserName(String input, String\u0026 user, String\u0026 domain)\r\n at System.Management.Automation.PSCredential.GetNetworkCredential()\r\n at CallSite.Target(Closure , CallSite , PSCredential )\r\n```","author":{"url":"https://github.com/Arnavion","@type":"Person","name":"Arnavion"},"datePublished":"2017-08-29T10:26:41.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/4696/PowerShell/issues/4696"}
| 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:b4c46ef8-2ca5-db27-d330-7f6d9838a23a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 883E:326E71:43BD8C:5B3970:6A580320 |
| html-safe-nonce | 77e2834388c51c2ceb7b8581b19a31f991b6cac2a27ee9c9fa6b8c34dc15a2c4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4ODNFOjMyNkU3MTo0M0JEOEM6NUIzOTcwOjZBNTgwMzIwIiwidmlzaXRvcl9pZCI6IjU1MzQ4NjUwODEyOTU3MDA3NjgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 84bc901201f675e4ce0d3a21d4691d68fd5289c9054820935de533018562b116 |
| hovercard-subject-tag | issue:253604257 |
| 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/4696/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ab8123be29a787f6f2ae25d51fc51a50e94ed502bc95987df7c4468784fadc74/PowerShell/PowerShell/issues/4696 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ab8123be29a787f6f2ae25d51fc51a50e94ed502bc95987df7c4468784fadc74/PowerShell/PowerShell/issues/4696 |
| og:image:alt | Steps to reproduce > [pscredential]::Empty.GetNetworkCredential() Expected behavior $null Per the docs, an "uninitialized" PSCredential object should return null MSDN also documents it as such, tho... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Arnavion |
| hostname | github.com |
| expected-hostname | github.com |
| None | 49c8c15fabcbf356d607a90ca115c13b273e42ff8b74155de050fd229a9b0121 |
| 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 | 3fb1f684e7a833eb1b2d01d39875a2b52cb4fe9b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width