Conversation
SteveL-MSFT
left a comment
There was a problem hiding this comment.
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.
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.