Shaun Ros
Shaun Ros

Reputation: 23

'Type is unsupported' error when trying to save Enum in DynamoDb

I have the below class that I have decorated with DynamoDb attributes:

[DynamoDBTable("Orders")]
public class OrderDynamoModel
{
    [DynamoDBHashKey]
    public int OrderId { get; set; }

    [DynamoDBProperty]
    public DateTime DateTimeUtc { get; set; }

    [DynamoDBProperty]
    public int TId { get; set; }

    [DynamoDBProperty]
    public OrderStatus Status { get; set; }

    [DynamoDBProperty]
    public string Order { get; set; }
}

[Flags]
public enum OrderStatus
{
    None = 0,
    Pending = 1,
    Completed = 2
}

When I try to save an instance of the class using DynamoDBContext.Save, I get the below error:

Type OrderStatus is unsupported, it cannot be instantiated

When I change the type of the property from OrderStatus to int and update the code accordingly, it can save the record in DynamoDb successfully.

Any idea why I can't use the enum?

Upvotes: 2

Views: 2625

Answers (1)

DavidG
DavidG

Reputation: 118987

You are using the old version of the AWS SDK, version 2, that hasn't been updated since 2016. You need to upgrade to version 3, at least version 3.1.1 as that is when enum type support was added.

See this AWS Blog for more information.

Upvotes: 1

Related Questions