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
When I have a collection initialized with an Enumerable.Empty then DeserializeObject throws:
Unhandled exception. Newtonsoft.Json.JsonSerializationException: Cannot create and populate list type System.Linq.EmptyPartition`1[System.String]. Path 'Values', line 1, position 11.
If I change the initialization to something else (such as new List<string>()) then it works. This worked in prior versions of .NET, but now seems to fail in .NET Core 3.
Full repo:
namespace ConsoleApp1
{
public class Foo
{
public IEnumerable<string> Values { get; set; } = Enumerable.Empty<string>();
}
class Program
{
static void Main(string[] args)
{
var f1 = new Foo { Values = new[] { "apple", "banana", "carrot" } };
var json = JsonConvert.SerializeObject(f1);
Console.WriteLine(json);
var f2 = JsonConvert.DeserializeObject<Foo>(json);
Console.WriteLine(f2.Values.Count());
}
}
}
The text was updated successfully, but these errors were encountered:
We tested and it seems it's working with the patch. Of course, the next question is what do you envision a release? Given that it breaks anyone using .NET Core 3 it seems an important patch to get out.
This still appears to be an issue, so same question as above re. an update. Our codebase makes extensive use of Json.NET functionality so switching to System.Text.Json isn't an appealing option.
When I have a collection initialized with an
Enumerable.Empty
thenDeserializeObject
throws:If I change the initialization to something else (such as
new List<string>()
) then it works. This worked in prior versions of .NET, but now seems to fail in .NET Core 3.Full repo:
The text was updated successfully, but these errors were encountered: