GaryJL
GaryJL

Reputation: 901

Windows Azure Service Bus - BrokeredMessage.Properties with Enum Value

I am trying to add a custom property to the BrokeredMessage.Properties collection before sending it to the Azure Service Bus. The custom property type is an enum:

[Serializable, DataContract]
public enum FooBar
{
    [EnumMember]
    Foo = 0,
    [EnumMember]
    Bar = 1
}

I have also tried numerous combinations of the Attributes, and a version with no Attributes.

This is the code which adds the property and sends the message:

var brokeredMessage = new BrokeredMessage(new MessageObject(){ //etc });
brokeredMessage.Properties.Add("FooBar", FooBar.Foo);
queueClient.Send(brokeredMessage);

The following error is returned when attempting to send the message:

System.Runtime.Serialization.SerializationException : Serialization operation failed due to unsupported type Namespace.FooBar.

I've tried to track down some more detailed documentation on the BrokeredMessage.Properties limitations (if any), and can't find anything which specifies that only primitive types can be used.

Any ideas as to why this doesn't work?

Edit:

Should have said I am using V2.1.0.0 of Microsoft.ServiceBus.

Upvotes: 9

Views: 4402

Answers (1)

user2399170
user2399170

Reputation: 620

Shortly, you can use only simple types like string, integers.

For your case, you can try two ways

  1. brokeredMessage.Properties.Add("FooBar", (int)FooBar.Foo);
  2. brokeredMessage.Properties.Add("FooBar", FooBar.Foo.ToString());

Choose by you self, which one is better for you.

Upvotes: 11

Related Questions