Why can't EventData.GetBytes() be called before sending?

I'm working with Azure Event Hubs and initially when sending data to try and calculate batch size I had code similar to the below that would call EventData.GetBytes

EventHubClient client;//initialized before the relevant code EventData curr = new EventData(data); //Setting a partition key, and other operations. long itemLength = curr.GetBytes().LongLength; client.SendAsync(curr);

Unfortunately I would receive an exception in the SDK code.

The message body cannot be read multiple times. To reuse it store the value after reading.

While removing the ultimately unnecessary call to GetBytes meant that I could send messages, the rationale for this exception to occur is rather puzzling. Calling GetBytes() twice in a row is an easy way to reproduce the same exception, but a single call will mean that the EventData cannot be sent successfully.

It seems likely that underneath a Message is used and this is set to throw an exception if called more than once as Message.GetBody documents; however, there is no documentation to this effect in EventData's methods GetBodyStream, GetBody w/serializer, GetBody, or GetBytes.

I imagine this should either be documented, or corrected since currently it is an unpleasant surprise in a separate thread.


Have you tried using EventData.SerializedSizeInBytes to get the size? that is a much more accurate way to get the size for batching calculation.


  • Wrap/Break list items in two ul
  • What is expected when I am told “Sort a singly linked list”
  • How to consume and replace a value in an &mut ref [duplicate]
  • Find all combination that sum to N with multiple lists
  • Docker: Error processing tar file(exit status 1): Error setting up pivot dir: not a directory
  • Avoid losing data type for the partitioned data when writing from Spark
  • SQL Keeping count of occurrences
  • Spark partitioning/cluster enforcing
  • Is there a way to maintain a 200MB immutable data structure in memory and access it from a script?
  • Service Fabric - how to gracefully fail an app
  • Producing n rows per group
  • AWS store MQTT message to DynamoDB
  • Number of ways to partition a number in Python
  • Does sql server minds the way records where inserted?
  • Azure Service Bus topics partitioning
  • Send the string to its hex equivalent
  • Oracle ListaGG, Top 3 most frequent values, given in one column, grouped by ID
  • Azure table query partial partitionkey guid match
  • Xamarin PCLCrypto SHA256 give different hash
  • Python cosine function precision [duplicate]
  • vectorized indexing/slicing in numpy/scipy?
  • How can I include If-None-Match header in HttpRequestMessage
  • Rest Services conventions
  • Merging rows to columns
  • WPF - CanExecute dosn't fire when raising Commands from a UserControl
  • Content-Length header not returned from Pylons response
  • Play WS (2.2.1): post/put large request
  • How to access EntityManager inside Entity class in EJB3
  • Why value captured by reference in lambda is broken? [duplicate]
  • Encrypt data by using a public key in c# and decrypt data by using a private key in php
  • vba code to select only visible cells in specific column except heading
  • 'TypeError' while using NSGA2 to solve Multi-objective prob. from pyopt-sparse in OpenMDAO
  • Convert array of 8 bytes to signed long in C++
  • Hazelcast - OperationTimeoutException
  • How get height of the a view with gone visibility and height defined as wrap_content in xml?
  • Why joiner is not used after Sequence generator or Update statergy
  • Linking SubReports Without LinkChild/LinkMaster
  • apache spark aggregate function using min value
  • Recursive/Hierarchical Query Using Postgres
  • UserPrincipal.Current returns apppool on IIS