How can I serialize a System.Collections.Immutable.ImmutableList<T>?
See original GitHub issueFor example, the following code will cause an exception, saying
The serializer for type ‘System.Collections.Immutable.ImmutableList`1[System.Int32]’ could not be found.
I suspect other immutable types won’t work either…
using ExtendedXmlSerializer;
using ExtendedXmlSerializer.Configuration;
using System.Collections.Immutable;
using System.IO;
class Test
{
public ImmutableList<int> List { get; }
public Test(ImmutableList<int> list)
{
List = list;
}
public void TestSerialize()
{
var serializer = new ConfigurationContainer()
.UseAutoFormatting()
.UseOptimizedNamespaces()
.EnableImplicitTyping(typeof(Test))
.EnableParameterizedContentWithPropertyAssignments()
.Create();
using var output = File.Create("test.xml");
serializer.Serialize(output, new Test(new[] { 1 }.ToImmutableList()));
}
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:14 (7 by maintainers)
Top Results From Across the Web
Make System.Collections.Immutable [Serializable] #14395
In my use case I'm trying to save some list of serializable objects to AppFabric cache. Serialization of generic List<> or array is...
Read more >How to serialize / deserialize immutable list type in c# - ...
The ImmutableList<T> type comes from the immutables library https://www.nuget.org/packages/Microsoft.Bcl.Immutable. Note that the class ...
Read more >Serializing Immutable Collections in .NET
Serialization and immutable collections do mix in .NET, but only if you look to third party libraries like JSON.NET and protobuf-net.
Read more >Supported collection types in System.Text.Json
Json. JsonSerializer supports a collection type for serialization if it: Derives from IEnumerable or IAsyncEnumerable<T> Contains elements that ...
Read more >How to use immutability in C# | InfoWorld
To create immutable DTOs, you can take advantage of a ReadOnlyCollection or the thread-safe immutable collection types in the System.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Alrighty, this has been deployed to NuGet here: https://www.nuget.org/packages/ExtendedXmlSerializer/
Please do let me know of any issues you find and I will take a look into them for you. Closing for now.
Yeah, now everything works as expected!