jamesmontemagno / InAppBillingPlugin

Cross-platform In App Billing Plugin for .NET
MIT License
651 stars 152 forks source link

Randomly Android.OS.RemoteException on service connected. #107

Closed fernandovm closed 6 years ago

fernandovm commented 6 years ago

Dear @jamesmontemagno, I have been receiving some times the unhandled exception: https://gist.github.com/fernandovm/7d8e300bc56caad4f799b48fd94ad5f9. I'm using the package 'Plugin.InAppBilling' version '1.2.4'.

Unfortunately I not have the steps to reproduce the behavior, I always run the below code on startup of my xamarin forms app (in a background thread), but its happens randomly (were rarely):

try
{
    //...
    if (await CrossInAppBilling.Current.ConnectAsync())
    {
        //...
        var purchases = (await CrossInAppBilling.Current.GetPurchasesAsync(prodType));
        //...
    }
    //...
}
catch (Exception e)
{
    if (e is AggregateException)
    {
        (e as AggregateException).Flatten().Handle(ex => return true);
    }
}
finally
{
    await CrossInAppBilling.Current.DisconnectAsync();
}

Are there some way as I can better help you investigate this issue?

jamesmontemagno commented 6 years ago

This is not recommended to do in startup or in a background thread as that could cause a lot of issues. Try moving code into some other place.

fernandovm commented 6 years ago

Hi @jamesmontemagno, in really I does not run the code in exactly in startup, but immediately after the startup. Thus I think that I must understand from your reply that I does not must invoke the code from a background thread, I must always invoke it from the main thread. It is? Thank you so much by your attention!