Task throws System.Reflection.TargetInvocationException

JassimRahmaJassimRahma USMember ✭✭✭✭
edited January 11 in Xamarin.Forms

Hi,

I am getting this error:

System.Reflection.TargetInvocationException: 'Exception has been thrown by the target of an invocation.'

Here is how I am getting it..

In my Click event, I am doing:

StackLayoutSignin.IsVisible = false;
BusyIndicatorSignin.IsVisible = true;
await Task.Run(SigninUser);

the SigninUser is:

async void SigninUser()
{
    var salt = await PasswordHash.GetPasswordSalt(TextBoxSigninEmailAddress.Text);
    ....................
    ....................
    ....................
    ....................
}

and the error occurs on this line:

var salt = await PasswordHash.GetPasswordSalt(TextBoxSigninEmailAddress.Text);

My GetPasswordSalt is here:

public static async Task<Tuple<string, string>> GetPasswordSalt(string email_address)
{
    // var client = new HttpClient();

    using (var client = new HttpClient())
    {
        client.BaseAddress = new Uri("https://www.my.com/salt.php");

        var content = new FormUrlEncodedContent(new[]
        {
            new KeyValuePair<string, string>("email", email_address)
        });

        var response = await client.PostAsync("https://www.my.com/salt.php", content);

        var result = await response.Content.ReadAsStringAsync();

        if (!String.IsNullOrWhiteSpace(result))
        {
            dynamic data = JsonConvert.DeserializeObject(result);

            salt_result = data[0].result.ToString();
            password_salt = data[0].password_salt.ToString();
        }
        else
        {
            password_salt = "X";
        }

        return new Tuple<string, string>(salt_result, password_salt);
    }
}

kindly help...

Thanks,
Jassim

Sign In or Register to comment.