I am looking at replacing the default serializer for RPC in ASF. This involves implementing a few interfaces, one of which is passed between services communicating via RPC
public interface IServiceRemotingResponseMessageBody
{
void Set(object response);
object Get(Type paramType);
}
As the implementation needs to be serializable, the obvious ProtoBuf implementation is something like
[ProtoContract]
public class ProtoBufRemotingResponseBody : IServiceRemotingResponseMessageBody
{
[ProtoMember(1)]
public object Value { get; set; }
public void Set(object response)
{
Value = response;
}
public object Get(Type paramType)
{
return Value;
}
}
Unfortunately this fails miserably with
No serializer defined for type: System.Object
Is there a workaround here? System.Object has no contract, but the OOTB DataContract
serializer can, as can MessagePack here, but these are not schematized which creates versioning headaches when using reliable collections. I have tried using a common base type, but Value can be IEnumerable<T>
or T
etc.
Can anyone help? Thanks, KH
At the moment, protobuf-net does not have good support for object
, except via some messy hacks. The simplest to try (just to see if it works for your scenario) is to find the "dynamic types" flag on that proto-member attribute and set it to true. This library-specific hack burns some type metadata into to data to allow it to work with unknown types, but it is far from perfect.
The "better" fix here would involve me finding the time to implement the "any" feature (added to the Google library relatively recently, around the time of proto3 IIRC). This works broadly similarly, but would be implemented in a cross-library way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With