-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Fix NRE in ConsiceView #11435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix NRE in ConsiceView #11435
Conversation
SteveL-MSFT
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible to add a test? Seems like we can create an ErrorRecord that hits this code path?
@SteveL-MSFT I did not find how to do it :-( |
|
@iSazonov seems like line 802 would have already covered this? Can you show how it looks before and after this change with your error? |
|
@iSazonov Can you provide a repro with your module? |
|
My fix is not right.
The line throws if ToString() throws ($prop.Value has a reference on an object with property with disposed object in my case) I will update the PR. |
SteveL-MSFT
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so it's calling a method on a disposed object.
...stem.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs
Show resolved
Hide resolved
|
Tried to simulate the original issue of a disposed object, but couldn't find a way to do it. |
I too. I could port a code from AccountManagement module but I think it is not correct behavior for ToString() to throw and I will report the issue to Core team. |
Use LanguagePrimitives.TryConvertTo() as last resort to string conversion.
|
🎉 Handy links: |
PR Summary
Use LanguagePrimitives.TryConvertTo() as last resort to string conversion.
PR Context
Playing with AccountManagement module I catch an error where properties with disposed object reference present.
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.