-
Notifications
You must be signed in to change notification settings - Fork 849
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Amazon DynamoDBContext - NET 7 AOT Incompatibilities #2542
Comments
Hi @rac146, Good afternoon. Thanks for opening the issue. Just wanted to check if you referred the blog post Building serverless .NET applications on AWS Lambda using .NET 7 for the Native AOT support. As mentioned, currently, the Thanks, |
Hey Ashish, Even excluding AWSSDK.DynamoDBv2 from trimming, the error still occurs. This error will present itself with or without trimming - this is flagged as an AOT analysis warning, not a trimming warning when running dotnet publish. |
Here are the detailed errors when running D:\JenkinsWorkspaces\trebuchet-stage-release\AWSDotNetPublic\sdk\src\Services\DynamoDBv2\Custom\Conversion\DynamoDBEntryConversion.cs(652): AOT analysis warning IL3050: Amazon.DynamoDBv2.Converter`1.d__0.MoveNext(): Using member 'System.Type.MakeGenericType(Type[])' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The native code for this instantiation might not be available at runtime. D:\JenkinsWorkspaces\trebuchet-stage-release\AWSDotNetPublic\sdk\src\Services\DynamoDBv2\Custom\Conversion\SchemaV1.cs(379): AOT analysis warning IL3050: Amazon.DynamoDBv2.CollectionConverter.d__1.MoveNext(): Using member 'System.Type.MakeArrayType()' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The code for an array of the specified type might not be available. D:\JenkinsWorkspaces\trebuchet-stage-release\AWSDotNetPublic\sdk\src\Services\DynamoDBv2\Custom\Conversion\SchemaV1.cs(382): AOT analysis warning IL3050: Amazon.DynamoDBv2.CollectionConverter.d__1.MoveNext(): Using member 'System.Type.MakeGenericType(Type[])' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The native code for this instantiation might not be available at runtime. D:\JenkinsWorkspaces\trebuchet-stage-release\AWSDotNetPublic\sdk\src\Services\DynamoDBv2\Custom\Conversion\SchemaV1.cs(384): AOT analysis warning IL3050: Amazon.DynamoDBv2.CollectionConverter.d__1.MoveNext(): Using member 'System.Type.MakeGenericType(Type[])' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The native code for this instantiation might not be available at runtime. |
I've got the current version of the AWSSDK working for now with DynamoDB if I add the following to the
Hope this helps other for now. |
Adding to @jesmiatka. I needed these lines additionally to make it work:
|
@MrZoidberg In which assembly is System.Nullable? Can you share the whole Assembly entry in |
In System.Runtime. Here the whole rd.xml:
|
Any updates on this one? Or maybe with regard to .NET 8? |
In my scenario (dotnet8, managed runtime) I've used @branog68 modifications, but had to exclude these three lines due to compilation errors:
After this fix, |
Although it doesn't fix the issue, this PR marked these as not compatible and has some explanation of what it would take to fix. Also, Microsoft recommends moving away from |
Hey @Beau-Gosse-dev , I may be missing it but can you point to where Microsoft are moving away from |
@beeradmoore There are other reference from Michal, but here is one: dotnet/runtime#72989 (comment) |
Perfect. Thanks @Beau-Gosse-dev |
Describe the bug
Was running some NET7 AOT experiments with DynamoDBContext and was receiving runtime errors after doing an AOT compilation:
Expected Behavior
For DynamoDB to be AOT NET 7 supported
Current Behavior
Errors out after dotnet publish in NET7 AOT mode
Reproduction Steps
Attempt to run any DynamoDB queries that use DynamoDBContext with latest version of AWS SDK
Possible Solution
Decided to hack into the SDK to find the culprit. Discovered .MakeGenericType is throwing the runtime errors.
Switched these 4 lines for experimentation purposes:
In
DynamoDBEntryConversion.cs
:Line 651:
var nullableType = typeof(Nullable<>).MakeGenericType(type)
Potential Fix?:
yield return typeof(Nullable<>);
In SchemaV1.cs:
Line 379:
yield return pt.MakeArrayType();
Fix?:
yield return typeof(Array);
Line 382:
yield return listType.MakeGenericType(pt);
Fix?:
yield return typeof(List<>);
Line 384:
yield return setType.MakeGenericType(pt);
Fix?:
yield return typeof(HashSet<>);
This allowed my test application to run and work correctly. Is this is right long-term fix to the problem? I don't know, but just wanted to let you know!
Additional Information/Context
With AWS starting to push AOT further, it would be great to start working through the bugs that prevent an AOT build from working. I believe this fits as a bug opposed to a feature request, especially with the push towards AOT compatible lambdas!
AWS .NET SDK and/or Package version used
AWS SDK DynamoDBv2 3.7.101.44
Targeted .NET Platform
.NET 7
Operating System and version
Windows 10
The text was updated successfully, but these errors were encountered: