question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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 #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

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
iSazonovcommented, Jan 15, 2021

PropertyGetterWorker method enumerates recursively and it is called for a value making conversion to enumerator with JValue.JValueDynamicProxy.TryConvert - the last method throw. I think only debug shows that happens in PropertyGetterWorker.

0reactions
iSazonovcommented, Jan 19, 2021

Since no regression is from Windows PowerShell I think it makes no sense to invest to NewtonSoft Json.NET. If there are other similar scenarios, then we can consider improving this PropertyGetterWorker method.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Could not load file or assembly 'Newtonsoft.Json' or one of ...
To solve this, I ensured all my projects used the same version by running the following command and checking the results:
Read more >
Migrate from Newtonsoft.Json to System.Text.Json - .NET
Json accepts non-string values, such as a number or the literals true and false , for deserialization to properties of type string.
Read more >
Newtonsoft Json package
I had to remove the newtonsoft.Json that some addons are using in my project, because in 2020.x it gets stuck in a loop...
Read more >
data binding and serialization issue with System.Text.Json ...
I am using the new System.Text.Json in asp.net core and I noticed that the grid does not bind to the model when using...
Read more >
Working with Newtonsoft.Json in C# & VB
In this article, we will see how to work with standard value types, custom value types, compress structures to types, and transform from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found