I have a simple class that looks like this:
[DataContract]
public class Actor
{
public string Email { get; set; }
public string Name { get; set; }
public Guid Id { get; set; }
}
And I’m trying to send it as a property in a BrokeredMessage like this:
BrokeredMessage message = new BrokeredMessage(entity);
message.Properties["entityType"] = entity.GetType().Name;
message.Properties["action"] = action;
message.Properties["actor"] = actor; // <-- This causes a failure
message.Properties["tenant"] = tenant;
topicClient.Send(message);
But I keep getting a SerializationException with the message
Serialization operation failed due to unsupported type Starlight.Events.Actor
I tried supplying my own serializer but it didn’t help:
var knownTypes = new List<Type>();
knownTypes.Add(typeof(Actor));
var dcs = new DataContractSerializer(entity.GetType(), knownTypes);
BrokeredMessage message = new BrokeredMessage(entity, dcs);
This still gives the same exception. What am I missing?
Have you checked that the DataContractSerializer is capable of correctly serializing / deserializing Actor class is serializable on it’s own?
If that’s the case, a second thing to check would be the size of the resulting serialized object. According to the BrokeredMessageProperties documentation, there’s a 342b limit on the size of every individual header, 64kb for all the combined properties, and 256kb for the entire message. If you exceed any of those, you’ll also get a SerializationException: