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.

How can I serialize a System.Collections.Immutable.ImmutableList<T>?

See original GitHub issue

For 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:closed
  • Created 3 years ago
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
Mike-E-angelocommented, Dec 8, 2020

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.

1reaction
lanyizicommented, Dec 7, 2020

Yeah, now everything works as expected!

Read more comments on GitHub >

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

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

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