0

Using Azure Service Fabric I'm trying to serialize Immutable types in stateful services and actors. Apparently there is no support in the data contract serializer but I could add it as shown here using an IDataContractSurrogate.

Is there some way to provide the serializer with my IDataContractSurrogate?

Community
  • 1
  • 1
Eli Pulsifer
  • 713
  • 9
  • 25
  • After looking at the KvsActorStateProvider it appears to be impossible without creating my own ActorStateProvider. This is because the constructor sets actorStateSerializer = new ActorStateProviderSerializer() and there is no way to change the ActorStateProviderSerializer or provide a custom implementation. – Eli Pulsifer Sep 29 '16 at 20:58
  • this is somewhat similar: http://stackoverflow.com/questions/35578005/hosting-console-application-in-public-service-fabric-cluster – Rotem Varon Sep 29 '16 at 22:04

1 Answers1

0

If you define your immutable type similar to this, it works fine:

[DataContract]
public class Payload
{
    [DataMember]
    public readonly string Content;

    public Payload(string content)
    {
        Content = content;
    }
}

see this article too.

LoekD
  • 11,402
  • 17
  • 27
  • I cant do that. I should have been more clear, when I said immutable types I was referring to System.Collections.Immutable types. – Eli Pulsifer Sep 30 '16 at 19:35
  • check that article.. they use an immutable collection – LoekD Oct 01 '16 at 16:11
  • Ok, I see that they have an IEnumerable member that is backed by an ImmutableList but that's different than directly serializing the ImmutableList. They have to rebuild the list in OnDeserialized. What I really want is the ability to store an immutable collection in a reliable actors storage. e.g. StateManager.SetStateAsync("list", myImmutableList); – Eli Pulsifer Oct 02 '16 at 17:39