Skip to content

DynamoDB AOT fails for type and collection properties #3646

Open
@dscpinheiro

Description

@dscpinheiro

@normj
I've tested AOT integration with 4.0.0-preview.6.
There were no AOT warnings, however apparently, it doesn't support type properties and collection properties.

  1. Nested Types:
var nestedTypeId = Random.Shared.Next().ToString();
await context.SaveAsync(new TypeWithNestedTypeProperty
{
    Id = nestedTypeId,
    Name = "Test",
    SubType = new SubType() { SubName = "Subname" }
});
Console.WriteLine("Item saved.");

var nestedItem = await context.LoadAsync<TypeWithNestedTypeProperty>(nestedTypeId);
Console.WriteLine($"Item loaded: {nestedItem}");
Console.WriteLine($"SubType.SubName: {nestedItem.SubType.SubName}");

[DynamoDBTable("TestTable")]
class TypeWithNestedTypeProperty
{
    [DynamoDBHashKey]
    public string Id { get; set; }
    public string Name { get; set; }
    public SubType SubType { get; set; }
}

class SubType
{
    public string SubName { get; set; }
}

Result:

Unhandled Exception: System.InvalidOperationException: Type SubType is unsupported, it cannot be instantiated
   at Amazon.DynamoDBv2.DataModel.StorageConfig..ctor(Type) + 0x14f
   at Amazon.DynamoDBv2.DataModel.ItemStorageConfig..ctor(Type) + 0x12
   at Amazon.DynamoDBv2.DataModel.ItemStorageConfigCache.CreateStorageConfig(Type, String, DynamoDBFlatConfig) + 0x43
   at Amazon.DynamoDBv2.DataModel.ItemStorageConfigCache.GetConfig(Type, DynamoDBFlatConfig, Boolean) + 0x144
   at Amazon.DynamoDBv2.DataModel.DynamoDBContext.SerializeToDocument(Object, Type, DynamoDBFlatConfig) + 0x2c
   at Amazon.DynamoDBv2.DataModel.DynamoDBContext.ToDynamoDBEntry(SimplePropertyStorage, Object, DynamoDBFlatConfig, Boolean) + 0x125
   at Amazon.DynamoDBv2.DataModel.DynamoDBContext.PopulateItemStorage(Object, ItemStorage, DynamoDBFlatConfig, Boolean, Boolean) + 0xe6
   at Amazon.DynamoDBv2.DataModel.DynamoDBContext.ObjectToItemStorage(Object, Type, Boolean, DynamoDBFlatConfig) + 0x7e
   at Amazon.DynamoDBv2.DataModel.DynamoDBContext.<SaveHelperAsync>d__48.MoveNext() + 0x5d
  1. Collection property:
var listTypeId = Random.Shared.Next().ToString();
await context.SaveAsync(new TypeWithCollectionProperty
{
    Id = listTypeId,
    Name = "Test",
    Items = new List<string> { "1", "2", "3" }
});
Console.WriteLine("Item saved.");

var collectionItem = await context.LoadAsync<TypeWithCollectionProperty>(listTypeId);
Console.WriteLine($"Item loaded: {collectionItem}");
Console.WriteLine($"Items: {string.Join(",", collectionItem.Items)}");

Result:

Unhandled Exception: System.InvalidOperationException: Cannot instantiate type System.Collections.Generic.List`1[[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]
   at Amazon.DynamoDBv2.DataModel.Utils.InstantiateHelper(Type, Type[][], Object[]) + 0x119
   at Amazon.DynamoDBv2.DataModel.Utils.ItemsToIList(Type, IEnumerable`1, Object&) + 0x42
   at Amazon.DynamoDBv2.Converter.TryFromEntry(DynamoDBEntry, Type, Object&) + 0x79
   at Amazon.DynamoDBv2.Converter.FromEntry(DynamoDBEntry, Type) + 0x39
   at Amazon.DynamoDBv2.DataModel.DynamoDBContext.FromDynamoDBEntry(SimplePropertyStorage, DynamoDBEntry, DynamoDBFlatConfig) + 0x7f
   at Amazon.DynamoDBv2.DataModel.DynamoDBContext.PopulateInstance(ItemStorage, Object, DynamoDBFlatConfig) + 0xc4
   at Amazon.DynamoDBv2.DataModel.DynamoDBContext.DocumentToObject(Type, ItemStorage, DynamoDBFlatConfig) + 0x47
   at Amazon.DynamoDBv2.DataModel.DynamoDBContext.DocumentToObject[T](ItemStorage, DynamoDBFlatConfig) + 0x32
   at Amazon.DynamoDBv2.DataModel.DynamoDBContext.<LoadHelperAsync>d__57`1.MoveNext() + 0x1c4

Attaching sample project:
DdbAORRepro.zip

Originally posted by @Dreamescaper in #3475

Metadata

Metadata

Assignees

No one assigned

    Labels

    aotAhead of TimebugThis issue is a bug.p2This is a standard priority issuequeuedv4

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions