In Service Fabric when an Actor is deactivated the actor object itself is being cleaned up. The state stored in the actor’s State Manager is not being removed in case of actor garbage collection. This is due to the fact that an actor is reactivated its data is again made available through the State Manager.
In our use case some of these actors are never being reactivated and therefore it is necessary to do ‘manual’ clean up of their data.
Deleting the Actor
To delete our Reliable Actor and his associated stated we used the code sample provided on docs.microsoft.com and used the function provided by the Actor Service to delete the actors from a remote caller.
When using the above code sample we ran into serialization errors.
Element ‘http://schemas.microsoft.com/2003/10/Serialization/:anyType’ contains data from a type that maps to the name ‘urn:ServiceFabric.Communication:ServiceResponseMessageHeaders’. The deserializer has no knowledge of any type that maps to this name. Consider using a DataContractResolver if you are using DataContractSerializer or add the type corresponding to ‘ServiceResponseMessageHeaders’ to the list of known types – for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to the serializer.
After some investigation we came to the conclusion that this issue was related to the incompatibility of V1 and V2 remoting in Service Fabric. The IActorService Proxy we assigned with the sample code of docs.microsoft.com was providing us with a V1 remoting endpoint.
To solve this, and to use the correct V2 remoting endpoint we used the implementation below.
Hope you find it helpful, someday!