SerializationException with new Reliable Actor projects in Visual Studio 2017


Recently, we released a pretty big update to the Service Remoting RPC communication library that includes changes to the message format between remote procedure calls. This means the old version isn't directly compatible with the new version - they can't read each other's messages. To make this work in a no-downtime rolling upgrade system like Service Fabric, we have to specify the new Service Remoting version explicitly on both the sender and receiver to ensure nothing breaks just by referencing the latest NuGet packages. This is done by adding an assembly attribute to specify the new version of Service Remoting, which looks like this:

[assembly: FabricTransportActorRemotingProvider(RemotingListener = RemotingListener.V2Listener, RemotingClient = RemotingClient.V2Client)]

The important thing with this is that both the sender and the receiver have to specify compatible versions of Service Remoting, otherwise you'll see errors like this:

SerializationException: 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.

The easiest way to make sure both sender and receiver are using the same version of Service Remoting is to put the that assembly attribute on your remoting interface class, because that remoting interface class is in an assembly that gets shared by both sender and receiver. In other words, it's saying the Service Remoting version is part of the contract.

This applies to Actor Services as well, because Actor Services are build on top of Reliable Services with Service Remoting. So the same rules apply, and here's where you might be running into trouble if you're creating a new Reliable Actor project with Visual Studio 2017 version 15.4. In the Actor project template, the attribute gets placed in the Actor Service project in Program.cs instead of the actor interface in the Actor.Interfaces project. So if you're seeing that SerializationException when you try to connect to a new Reliable Actor project using ActorProxy, you can fix it by simply moving the assembly attribute from Program.cs in the Actor service project to the IActor interface in the Actor.Interfaces project:

[assembly: FabricTransportActorRemotingProvider(RemotingListener = RemotingListener.V2Listener, RemotingClient = RemotingClient.V2Client)]
namespace Actor1.Interfaces
{
    /// 
    /// This interface defines the methods exposed by an actor.
    /// Clients use this interface to interact with the actor that implements it.
    /// 
    public interface IActor1 : IActor
    {
...

Then everything should work normally, until we get an updated project template out in an upcoming release of Visual Studio 2017.


Comments (0)

Skip to main content