Reputation: 3063
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?
Upvotes: 2
Views: 5526
Reputation: 5391
I arrived here as a result of a similar error on the newer ServiceBus message type which has 'UserProperties' instead of the 'Properties' collection found on the older BrokeredMessage type. Reading the documentation here there is a limited set of supported types that can be added as a user property. Perhaps the same rules apply to BrokeredMessage user properties.
Remarks: Only following value types are supported: byte, sbyte, char, short, ushort, int, uint, long, ulong, float, double, decimal, bool, Guid, string, Uri, DateTime, DateTimeOffset, TimeSpan
Upvotes: 1
Reputation: 2405
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:
As indicated in Windows Azure AppFabric Service Bus Quotas, the maximum size for each property is 32K. Cumulative size of all properties cannot exceed 64K. This applies to the entire header of the BrokeredMessage, which has both user properties as well as system properties (such as SequenceNumber, Label, MessageId, and so on). The space occupied by properties counts towards the overall size of the message and its maximum size of 256K. If an application exceeds any of the limits mentioned above, a SerializationException exception is generated, so you should expect to handle this error condition.
Upvotes: 0