Plc Worker
Plc Worker

Reputation: 101

Why does AmazonCognitoIdentityProviderClient deadlock in C# Xamarin?

I have used the aws-samples example named aws-cognito-dot-net-desktop-app in C# and WPF in a Windows PC application:

aws-cognito-dot-net-desktop-app

It works very well and correctly registers the user in Cognito.

Now, I'm using the same code for an Android application with C#.

To register a user, do the following:

bool success = await helper.SignUpUser(etUserName.Text, etPasswordUser.Text, etEmailUser.Text, etPhoneUser.Text);

SignUpUser is as follows:

internal async Task <bool> SignUpUser (string username, string password, string email, string phonenumber)
{

   Amazon.CognitoIdentityProvider.AmazonCognitoIdentityProviderClient provider =
                     new Amazon.CognitoIdentityProvider.AmazonCognitoIdentityProviderClient(new 
   Amazon.Runtime.AnonymousAWSCredentials());

   SignUpRequest signUpRequest = new SignUpRequest();

   ....
}

But in this part, when it comes to creating provider, the code freezes:

deadlock

No exception or some other type of error occurs.

Is there a way to find out with Visual Studio what is happening?

Any comment or suggestion is welcome.

UPDATE

The way I call SignUpUser is like this:

private async void clickCreateUser(object o, EventArgs e)
{
   ...
   try
   {

      CognitoHelper helper = new CognitoHelper();
      bool success = await helper.SignUpUser(etUserName.Text, etPasswordUser.Text, etEmailUser.Text, etPhoneUser.Text);
      ...

   }
   catch (Exception ex)
   {
    Android.Widget.Toast.MakeText(Application.Context, "Error: " + ex.Message, Android.Widget.ToastLength.Long).Show();
   }
}

UPDATE2

I got an example for Xamarin. Forms of this link:

xamarinforms-awscognito

When reviewing the code and seeing how a provider is created, I changed the code to as follows:

Amazon.CognitoIdentityProvider.AmazonCognitoIdentityProviderClient provider = new Amazon.CognitoIdentityProvider.AmazonCognitoIdentityProviderClient(/*new Amazon.Runtime.AnonymousAWSCredentials()*/new AnonymousAWSCredentials(), RegionEndpoint.USEast1);

Now the code doesn't freeze and goes to the next line:

enter image description here

I need to keep going through the rest of the code to determine other possible issues

Upvotes: 1

Views: 738

Answers (1)

Plc Worker
Plc Worker

Reputation: 101

The solution is to set the AWS region that is being used, as follows:

Amazon.CognitoIdentityProvider.AmazonCognitoIdentityProviderClient provider = new Amazon.CognitoIdentityProvider.AmazonCognitoIdentityProviderClient(new AnonymousAWSCredentials(), RegionEndpoint.YourRegionAWS);

Upvotes: 1

Related Questions