Skip to content

Working directly with certain .NET types, such as Newtonsoft.Json's, is broken: output formatting #10650

@mklement0

Description

@mklement0

Note:

  • I don't know whether / what other libraries are affected, or whether Newtonsoft.Json is an unusual one.

  • The bug surfaces only if the input JSON text contains an array.

  • The bug is a regression from Windows PowerShell, where it doesn't surface.

  • The error is ultimately the same as in Working directly with certain .NET types, such as Newtonsoft.Json's, is broken: implicit stringification #10652: Target type System.Collections.IEnumerator is not a value type or a non-abstract class. (Parameter 'targetType') - note how the type name is an interface, not a class.

Steps to reproduce

# Parse JSON text into a [JObject] instance.
# Note: To surface the bug, the text must contain an ARRAY
$obj = [Newtonsoft.Json.JsonConvert]::DeserializeObject('{ "foo": [ "bar" ] }')

# Apply default output formatting, which fails due to the bug:
{ $obj | Out-String } | Should -Not -Throw

Expected behavior

The test should succeed.

Actual behavior

The test fails, because the implicit output formatting threw an exception.

Target type System.Collections.IEnumerator is not a value type or a non-abstract class. 
(Parameter 'targetType')
PowerShell Core 7.0.0-preview.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-No ActivityIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtime

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions