You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ConvertTo-Json cmdlet hangs with -Depth 10 for object created using Get-Content #6388
Hi ILAVELAN KANNIAPPAN (@ikanni) - I suspect it's not actually hanging - it's just descending very deeply into the object tree which takes a very, very long time. Just take a look at the output from: ConvertTo-Json -InputObject $textContent -Depth 3
It's converting two PSObjects wrapping strings. These objects have a lot of extra metadata added by Get-Content:
Each additional level of depth will introduce more fields that will then need to be serialized. To get to depth 10, you'll be nesting very deeply into the object tree and it will seem to hang. If you call Get-Content with the -Raw flag, your example completes immediately:
Agree with Bruce Payette (@BrucePay) that the cmdlet is doing what it is supposed to. Perhaps Get-Content should be returning an array of strings and not objects (separate issue).
The actual bug is that ConvertTo-Json doesn't implement StopProcessing() to Ctrl+C doesn't break out.
Steve Lee (@SteveL-MSFT) Looking at the code, I don't think StopProcessing() is appropriate because the thread is not blocked. Adding checks to Stopping in the inner loops should be sufficient.
Dongbo Wang (@daxian-dbw) Right - it would still return PSObjects but we could stop adding the extra metadata by default. This is a conceptually significant breaking change but in practice I don't think anyone would notice (except that Get-Content performance and memory foot print would suddenly improve.)
Dongbo Wang (@daxian-dbw)Bruce Payette (@BrucePay)Steve Lee (@SteveL-MSFT) Get-Content adds several NoteProperties, including PSDrive and PSProvider or extra metadata by default. Whether we will fix the Get-Content in future release to remove the several NoteProperties or extra metadata ? I understand it is breaking change.
Activity
BrucePay commentedon Mar 13, 2018
Hi ILAVELAN KANNIAPPAN (@ikanni) - I suspect it's not actually hanging - it's just descending very deeply into the object tree which takes a very, very long time. Just take a look at the output from:
ConvertTo-Json -InputObject $textContent -Depth 3It's converting two
PSObjectswrapping strings. These objects have a lot of extra metadata added byGet-Content:Each additional level of depth will introduce more fields that will then need to be serialized. To get to depth 10, you'll be nesting very deeply into the object tree and it will seem to hang. If you call
Get-Contentwith the-Rawflag, your example completes immediately:Using
-RawtellsGet-Contentto not add all of the extra metadata, reducing the amount of work that needs to be done to serialize the objects.SteveL-MSFT commentedon Mar 14, 2018
Agree with Bruce Payette (@BrucePay) that the cmdlet is doing what it is supposed to. Perhaps
Get-Contentshould be returning an array of strings and not objects (separate issue).The actual bug is that
ConvertTo-Jsondoesn't implement StopProcessing() to Ctrl+C doesn't break out.daxian-dbw commentedon Mar 14, 2018
Get-Contentdoes return an array of strings, but it adds several NoteProperties to the string, includingPSDriveandPSProviderthat point to objects.BrucePay commentedon Mar 14, 2018
Steve Lee (@SteveL-MSFT) Looking at the code, I don't think
StopProcessing()is appropriate because the thread is not blocked. Adding checks toStoppingin the inner loops should be sufficient.Dongbo Wang (@daxian-dbw) Right - it would still return
PSObjectsbut we could stop adding the extra metadata by default. This is a conceptually significant breaking change but in practice I don't think anyone would notice (except thatGet-Contentperformance and memory foot print would suddenly improve.)BrucePay commentedon Mar 14, 2018
Marked as a bug for the need to support
Stoppingin the cmdlet.ikanni commentedon Mar 21, 2018
Dongbo Wang (@daxian-dbw) Bruce Payette (@BrucePay) Steve Lee (@SteveL-MSFT) Get-Content adds several NoteProperties, including PSDrive and PSProvider or extra metadata by default. Whether we will fix the Get-Content in future release to remove the several NoteProperties or extra metadata ? I understand it is breaking change.
markekraus commentedon Mar 21, 2018
ILAVELAN KANNIAPPAN (@ikanni) as a workaround you can do something like this:
I suggest opening a separate issue or locating an existing open issue and voting/commenting on it.