Posts

Showing posts from January, 2024

AWS DynamoDB SDK support for .NET DateTimeOffset

The AWS DynamoDB SDK does not support the .NET DateTimeOffset datatype by default . You may have received an exception similar to: System.InvalidOperationException: Type System.Nullable System.DateTimeOffset is unsupported, it cannot be instantiated. at Amazon.DynamoDBv2.DataModel But you can add a custom IPropertyConverter so that you can persist DateTimeOffset. public class DateTimeOffsetPropertyConverter : IPropertyConverter {     public static readonly string DateTimeOffsetPersistenceFormatString = "yyyy-MM-ddTHH:mm:ss.ffffzzz";     public object FromEntry(DynamoDBEntry entry)     {         if (entry == null)         {             throw new ArgumentNullException(nameof(entry));         }         var primitive = entry as Primitive;         if (primitive == null)         {             throw new ArgumentException($"{nameof(entry)} [{entry?.GetType()?.Name}] is not an instance of {nameof(Primitive)}.");         }         var dateString = primitive.Value as string;