pardahlman / RawRabbit

A modern .NET framework for communication over RabbitMq
MIT License
747 stars 144 forks source link

PublishAsync fails with PublishConfirmException if anonymous type is used #376

Open ChristianSauer opened 6 years ago

ChristianSauer commented 6 years ago

Sample code:

` [DataContract] public class EmailRequest { [DataMember] public string UserId { get; set; }

    [DataMember]
    public string TemplateName { get; set; }

    [DataMember]
    public Dictionary<string, object> Variables { get; set; }
}
    {
        var message = new EmailRequest()
        {
            UserId = userId,
            TemplateName = templateName,
            Variables = new Dictionary<string, object>()
            {
                {"id", calculationId},
                {"calculation", calculationName}
            }
        };

        await _busClient.PublishAsync(message, ctx => ctx
            .UsePublishConfiguration(cfg => cfg
                .WithRoutingKey("email.send")
                .OnExchange("fastgenomics")));`

This will work, but using this fails with a PublishConfirmException:

` { var message = new { UserId = userId, TemplateName = templateName, Variables = new Dictionary<string, object>() { {"id", calculationId}, {"calculation", calculationName} } };

        await _busClient.PublishAsync(message, ctx => ctx
            .UsePublishConfiguration(cfg => cfg
                .WithRoutingKey("email.send")
                .OnExchange("fastgenomics")));`
pardahlman commented 6 years ago

Thanks for reporting this. I wonder if there is something else going wrong causing the exception to be thrown. Could you try to do the same, but make sure that the exchange fastgenomics isn't declared? It would also be helpful if you could create a unit test that demonstrates the issue. Thanks!