-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Closed
Labels
Milestone
Description
Similar to this issue with empty enumerables, an IEnumerable that is actually backed by a LINQ OrderBy expression can no longer be serialized by DataContractSerializer in .NET Core.
This change in behavior breaks a lot of existing code at runtime.
The following code sample illustrates the problem. It works fine .NET Framework but fails on .NET Core 3.1.
namespace Test
{
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
[DataContract]
public class TestClass
{
[DataMember]
public IEnumerable<string> Stuff { get; set; }
}
class Program
{
static void Main()
{
TestClass t = new TestClass
{
Stuff = new List<string> { "a", "b", "c" }.OrderBy(x => x)
};
DataContractSerializer dcs = new DataContractSerializer(typeof(TestClass));
using MemoryStream stream = new MemoryStream();
dcs.WriteObject(stream, t);
}
}
}
Reactions are currently unavailable