Sending messages in batch mode over AMQP seems to throw InvalidOperationException with the 1.21.2 version of the SDK. This is a regression, and does not repro with 1.20.3 version of the SDK. This does not repro with MQTT.
static async Task SendAmqpMessages(string connectionString)
{
var dc = DeviceClient.CreateFromConnectionString(connectionString);
await dc.OpenAsync();
var msgs = new List<Message>();
for (int i = 0; i < 2; i++)
{
msgs.Add(new Message());
}
await dc.SendEventBatchAsync(msgs);
}
System.AggregateException
HResult=0x80131500
Message=One or more errors occurred. (Operation is not valid due to the current state of the object.)
Source=System.Private.CoreLib
StackTrace:
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.Wait()
at SDKTest1212.Program.Main(String[] args) in C:\Users\vpuranik.REDMOND\source\repos\SDKTest1212\Program.cs:line 14
Inner Exception 1:
InvalidOperationException: Operation is not valid due to the current state of the object.
This issue has been around for a while, see #1061
I don't know why it has not been fully acknowledged as it is a major issue.
adding my quick debug results (note that AmqpMessage.cs was looked up on GitHub and I did not reconcile it with the actual version - it might be different with an older implementation)

@vipeller Thanks for the help to address this issue. We're now waiting for AMQP library to release a new version from their master to resolve this issue. Meanwhile as you mentioned there are some API break changes in AMQP product, we should make sure those get address before they release.
This issue is root caused to underlying AMQP library. We are waiting for them to release alatest version to update the dependency.
@ntrpnr, @davilu, @prmathur-microsoft, thank you for your contribution to our open-sourced project! Please help us improve by filling out this 2-minute customer satisfaction survey