Description
Describe the bug
We have a MAUI app (for Android and iOS), where users can sign in. Our CIAM provider is AWS Cognito. Users can sign in via email address/password or via Federated Identity (Apple, Google).
That used to work just fine, but when we upgraded our AWS NuGet packages to newer versions, the email/password login seems to work no more. Instead we get the following error message "The type initializer for 'Amazon.Runtime.Internal.Util.ChecksumUtils' threw an exception."
This exception seems to be thrown when we call the following method (probably on StartWithSrpAuthAsync
):
internal static async Task<SignInResponse> SignIn(string email, string password)
{
StatusCode statusCode;
try
{
using var providerClient = new AmazonCognitoIdentityProviderClient(new AnonymousAWSCredentials(), RegionEndpoint.EUCentral1);
var userPool = new CognitoUserPool(MainConstants.AWS_USER_POOL_ID, MainConstants.AWS_USER_POOL_CLIENT_ID, providerClient);
var user = new CognitoUser(email, MainConstants.AWS_USER_POOL_CLIENT_ID, userPool, providerClient);
var authRequest = new InitiateSrpAuthRequest()
{
Password = password
};
AuthFlowResponse response = await user.StartWithSrpAuthAsync(authRequest).ConfigureAwait(false);
var result = new SignInResponse()
{
AWSCognitoResponseSignIn = response,
AccessToken = response.AuthenticationResult.AccessToken,
StatusCode = new(HttpStatusCode.OK),
};
return result;
}
catch (Exception ex)
{
statusCode = new((int)HttpStatusCode.BadRequest, ex.Message);
return new() { StatusCode = statusCode };
}
}
For some reason, that error only occurs in the "Release" version for iOS. - Android is not affected at all. - Works also just fine when called from a simple app like a console application. - In "Debug" mode it also works just fine for iOS. - Therefore, we assume that it might be related to AOT-compatibility and trimming (which seems to be used for iOS releases already, but is somewhat in beta for Android still).
What else?
- If we switch back to older AWS Nugets, it works again (also in "Release" mode on iOS). It works when we have AWSSDK.Core as a transitive package in version 3.7.304.31 (and versions before that of course). Version 3.7.400.13 seems also to be just fine.
- At least since AWSSDK.Core version 3.7.402.4 it seems to not work anymore (and throws the exception mentioned above). I also saw that there were indeed some changes made in the ChecksumUtils class "recently".
- I also follow the AWSSDK's V4 Development Tracker. Because that preview version also addresses AOT-compatibility issues, I also tried the AWSSDK.Core version 4.0.0-preview.8, but that, unfortunately, just throws the same exception.
Regression Issue
- Select this option if this issue appears to be a regression.
Expected Behavior
Sign-in via StartWithSrpAuthAsync
method throws no exception (for "Release" mode on iOS), but succeeds and returns a valid AuthFlowResponse
(as in previous AWSSDK.Core versions).
Current Behavior
Sign-in via StartWithSrpAuthAsync
method throws the following exception (for "Release" mode on iOS): "The type initializer for 'Amazon.Runtime.Internal.Util.ChecksumUtils' threw an exception."
Reproduction Steps
- Create an AWS Cognito user pool.
- Create a new user in that user pool (and confirm his email address).
- Create a new MAUI app, which uses the `StartWithSrpAuthAsync``method for sign-in, and which uses the problematic AWSSDK.Core either as a direct NuGet reference or as a transitive package.
- Create a release version of that MAUI app for iOS.
- Install the iOS app on your iPhone.
- Test the iOS app and its sign-in functionality on your iPhone. On sign-in, the exception will occur.
Possible Solution
Re-check your latest changes in class 'Amazon.Runtime.Internal.Util.ChecksumUtils'. (Current issue might be related to AOT-compatibility and trimming,)
Additional Information/Context
Problem only occurs in "Release" mode on iOS. ("Debug" mode and Android/Linux/Windows not affected).
AWS .NET SDK and/or Package version used
AWSSDK.Core 3.7.402.4 or AWSSDK.Core 4.0.0-preview.8 => Exception occurs with both versions.
Targeted .NET Platform
.NET 9.0
Operating System and version
iOS