State Manager. Try Add State Serializer<T>(IStateSerializer<T>) Method
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Registers a custom serializer for all reliable collections.
public bool TryAddStateSerializer<T> (Microsoft.ServiceFabric.Data.IStateSerializer<T> stateSerializer);
abstract member TryAddStateSerializer : Microsoft.ServiceFabric.Data.IStateSerializer<'T> -> bool
Public Function TryAddStateSerializer(Of T) (stateSerializer As IStateSerializer(Of T)) As Boolean
Type that will be serialized and deserialized.
The state serializer to be added.
True if the custom serializer was added. False if a custom serializer for the given type already exists.
When a reliable collection needs to serialize an object, it asks the state manager for a serializer for the given type. The state manager will first check if there is a custom serializer registered for the input type. If not, it will check if one of the built-in serializers can serialize the type. The state manager has built-in serializers for the following types: guid, bool, byte, sbyte, char, decimal, double, float, int, uint, long, ulong, short, ushort and string. If not, it will use System.Runtime.Serialization.DataContractSerializer.
Serializers must be infinitely forwards and backwards compatible. For the types that are using built-in serializers, Service Fabric ensures forwards and backwards compatibility. However, if a custom serializer is added for a type with a built-in serializer, the custom serializer must be compatible with the built-in serialization format for that type.
This method should be called from the constructor of the Stateful Service. This ensures that the Reliable Collections have the necessary serializers before recovery of the persisted state begins.