Skip to content

Commit dbc7589

Browse files
authored
Add warning about possible trimmed nested types for DataModel (#3668)
1 parent 8fbb1c9 commit dbc7589

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"services": [
3+
{
4+
"serviceName": "DynamoDBv2",
5+
"type": "Patch",
6+
"changeLogMessages": [
7+
"Improved error message in DataModel when in Native AOT mode and nested types have been trimmed."
8+
]
9+
}
10+
]
11+
}

sdk/src/Services/DynamoDBv2/Custom/DataModel/InternalModel.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,22 @@ private static Dictionary<string, MemberInfo> GetMembersDictionary([DynamicallyA
324324
internal StorageConfig([DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)] Type targetType)
325325
{
326326
if (!Utils.CanInstantiate(targetType))
327-
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture,
328-
"Type {0} is unsupported, it cannot be instantiated", targetType.FullName));
327+
{
328+
string errorMessage;
329+
if (InternalSDKUtils.IsRunningNativeAot())
330+
{
331+
errorMessage = $"Type {targetType.FullName} is unsupported, it cannot be instantiated. Since the application is running in Native AOT mode the type could possibly be trimmed. " +
332+
"This can happen if the type being created is a nested type of a type being used for saving and loading DynamoDB items. " +
333+
$"This can be worked around by adding the \"[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof({targetType.FullName}))]\" attribute to the constructor of the parent type." +
334+
"If the parent type can not be modified the attribute can also be used on the method invoking the DynamoDB sdk or some other method that you are sure is not being trimmed.";
335+
}
336+
else
337+
{
338+
errorMessage = $"Type {targetType.FullName} is unsupported, it cannot be instantiated";
339+
}
340+
341+
throw new InvalidOperationException(errorMessage);
342+
}
329343

330344
TargetType = targetType;
331345
Properties = new List<PropertyStorage>();

0 commit comments

Comments
 (0)