[Bug Report] Invalid cast on CreationTimeUtc
nikoraes opened this issue · 2 comments
Context
- Application's .NET Target Framework : net6
- SDK version used: v2.0.0-preview002
- Transport: AMQP (TCP)
Description of the issue
CreationTimeUtc type in Microsoft.Azure.Devices.Client.TelemetryMessage is of DateTimeOffset type.
UpdateAmqpMessageHeadersAndProperties tries to cast the CreationTimeUtc system property to DateTime (before converting it to an ISO string), which doesn't work.
Would be better to use the typed properties of the TelemetryMessage instead of casting from the SystemProperties.
Code sample exhibiting the issue
DateTimeOffset creationTimeUtc = ...
var message = new TelemetryMessage(payload)
{
CreatedOnUtc = creationTimeUtc
};
deviceClient.SendTelemetryAsync(message);
Console log of the issue
Follow the instructions here to capture SDK logs.
Don't forget to remove any connection string information!
Exception has occurred: CLR/System.InvalidCastException
Exception thrown: 'System.InvalidCastException' in System.Private.CoreLib.dll: 'Unable to cast object of type 'System.DateTimeOffset' to type 'System.DateTime'.'
at Microsoft.Azure.Devices.Client.Transport.AmqpIot.AmqpIotMessageConverter.UpdateAmqpMessageHeadersAndProperties(AmqpMessage amqpMessage, TelemetryMessage data, Boolean copyUserProperties)
at Microsoft.Azure.Devices.Client.Transport.AmqpIot.AmqpIotMessageConverter.OutgoingMessageToAmqpMessage(TelemetryMessage message)
at Microsoft.Azure.Devices.Client.Transport.AmqpIot.AmqpIotSendingLink.<SendMessageAsync>d__9.MoveNext()
at Microsoft.Azure.Devices.Client.Transport.AmqpIot.AmqpUnit.<SendMessageAsync>d__39.MoveNext()
at Microsoft.Azure.Devices.Client.Transport.AmqpIot.AmqpUnit.<SendTelemetryAsync>d__48.MoveNext()
at Microsoft.Azure.Devices.Client.Transport.Amqp.AmqpTransportHandler.<SendTelemetryAsync>d__17.MoveNext()
at Microsoft.Azure.Devices.Client.Transport.ErrorDelegatingHandler.<>c__DisplayClass18_0.<<ExecuteWithErrorHandlingAsync>b__0>d.MoveNext()
at Microsoft.Azure.Devices.Client.Transport.ErrorDelegatingHandler.<ExecuteWithErrorHandlingAsync>d__19`1.MoveNext()
at Microsoft.Azure.Devices.Client.Transport.RetryDelegatingHandler.<>c__DisplayClass14_0.<<SendTelemetryAsync>b__0>d.MoveNext()
at Microsoft.Azure.Devices.Client.RetryHandler.<>c__DisplayClass3_0.<<RunWithRetryAsync>g__TaskWrapper|0>d.MoveNext()
at Microsoft.Azure.Devices.Client.RetryHandler.<RunWithRetryAsync>d__5`1.MoveNext()
at Microsoft.Azure.Devices.Client.RetryHandler.<RunWithRetryAsync>d__3.MoveNext()
at Microsoft.Azure.Devices.Client.Transport.RetryDelegatingHandler.<SendTelemetryAsync>d__14.MoveNext()
at Microsoft.Azure.Devices.Client.IotHubBaseClient.<SendTelemetryAsync>d__31.MoveNext()
Thanks for bringing this to our attention; we'll put out a fix for this in our next release.
Your suggestion about retrieving the value from the typed property rather than the property map is valid, however, we've decided to go with the current approach since we're required to access all initialized properties for some features to work. Instead of having to go through each typed property explicitly, it is easier to enumerate through the list.
The current bug was a gap at our end that was introduced when we updated the return type of the typed property but didn't update the converter code. We've inspected our code to make sure this gap isn't present for the other implementations.
This has been fixed in the latest release of https://github.com/Azure/azure-iot-sdk-csharp/releases/tag/2023-03-13-v2preview