我有一个简单的类,如下所示:
[DataContract]
public class Actor
{
public string Email { get; set; }
public string Name { get; set; }
public Guid Id { get; set; }
}
我正在尝试将其作为 BrokeredMessage 中的属性发送,如下所示:
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);
但我不断收到一条SerializationException
消息
Serialization operation failed due to unsupported type Starlight.Events.Actor
我尝试提供自己的序列化程序,但没有帮助:
var knownTypes = new List<Type>();
knownTypes.Add(typeof(Actor));
var dcs = new DataContractSerializer(entity.GetType(), knownTypes);
BrokeredMessage message = new BrokeredMessage(entity, dcs);
这仍然给出了同样的例外。我错过了什么?