Skip to content
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

Object reference not set to an instance of an object on ConnectAsync #71

Closed
egimbernat opened this issue Aug 19, 2017 · 15 comments
Closed

Comments

@egimbernat
Copy link

I have tried several way and always I getting the error. I have all configured, the Billing permission, app on alpha and compiling against api 26.

Bug Information

Version Number of Plugin: 1.2.2
Device Tested On: Samsung Galaxy S7 Edge
Version of VS: 2017 Enterprise - 15.3.1
Version of Xamarin: 4.6

StackTrance = https://gist.github.com/egimbernat/991b516159329d528696d042fc5619d8

Steps to reproduce the Behavior

Try to ConnectAsync and error ocurrs.

Expected Behavior

Connects successfully

Actual Behavior

Exception is thrown

Code snippet

var billing = CrossInAppBilling.Current;
           try
           {
               var connected = await billing.ConnectAsync();

               if (!connected)
               {
                   return;
               }

               var subscriptions = await billing.GetProductInfoAsync(ItemType.Subscription, prods.Where(p => p.Type == 1).Select(c => c.Id).ToArray());

               foreach (var item in subscriptions)
               {
                   var prod = prods.First(p => p.Id == item.ProductId);
                   prod.Name += $" - {item.LocalizedPrice} {item.CurrencyCode}";
                   AvailableProducts.Add(prod);
               }

           }
           catch (InAppBillingPurchaseException pEx)
           {
               ProcessInAppBillingException(pEx);
           }
           catch (Exception ex)
           {
               ex.Process();
           }
           finally
           {
               await billing.DisconnectAsync();
           }

Screenshotst

@jamesmontemagno
Copy link
Owner

Have you read through this: https://jamesmontemagno.github.io/InAppBillingPlugin/TestingAndTroubleshooting.html your app most likely isn't configured correct.

@egimbernat
Copy link
Author

Yes I have readed it, but not succeed :( In fact is not a new app, I had an existing implementation of InApp Billing, so for sure it was working, I re-made the app and now I using the plugin.

The unique difference I saw, is that I'm using Net.Standard instead of PCL and Package Reference on the host projects, something like this:

    <CopyNuGetImplementations>true</CopyNuGetImplementations>
    <RestoreProjectStyle>PackageReference</RestoreProjectStyle>

@acrabb
Copy link

acrabb commented Aug 24, 2017

I'm seeing the same issue. I went through the configuration you linked @jamesmontemagno.
VS says the Null Ref is on Plugin.InAppBilling.Android/InAppBillingImplementation.cs:589 which is if (Context.PackageManager.QueryIntentServices(serviceIntent, 0).Any())

Any thoughts? Do we need to be on API 26?
What more info do you need?

@jamesmontemagno
Copy link
Owner

It is impossible to be on API 26 as we don't support it yet.

@jamesmontemagno
Copy link
Owner

You should not be compiling against API 26 at all, that would be a terrible idea.

I will take a look at that code though, do you know which part is the null ref exception?

@egimbernat
Copy link
Author

I do, it's the Context. I will downgrade the API and will inform the result.

@jamesmontemagno
Copy link
Owner

Did you remove the MainApplication.cs file that was added to your app?

https://github.com/jamesmontemagno/InAppBillingPlugin/blob/master/src/Plugin.InAppBilling.Android/InAppBillingImplementation.cs#L47

this grabs your current activity that is active.

@egimbernat
Copy link
Author

No, I left it as is installed. Let me downgrade some things, test it and return with a verdict if all went fine.

@jamesmontemagno
Copy link
Owner

Make sure that the currentactivity is being set as it is required

@egimbernat
Copy link
Author

Ok, so I downgrade all to compile against API 25, it's important to remove API 26 and Tools in order to work (Terrible idea to have this API right now installed).
Even that Current context was setting always was null on the Connect method.
Now works fine.

@jamesmontemagno
Copy link
Owner

Glad you got it working. I will test this out with the SDKs, but only API 25 is supported currently.

@acrabb
Copy link

acrabb commented Aug 25, 2017

I just got it working too. Turns out our project already depended on Plugin.CurrentActivity and whoever added it before must have removed MainApplication.cs

@EmilAlipiev
Copy link

@jamesmontemagno Does plugin already support api level 26 or 27?

@jamesmontemagno
Copy link
Owner

yup

@EmilAlipiev
Copy link

I am seeing this exception on my production as well. I have tested with 2 different accounts on 2 different android phones and my tests were successful. I cant get purchases, however I see some users get this exception as below. What could be the possible reason?


System.NullReferenceExceptionObject reference not set to an instance of an object
Raw
  at Plugin.InAppBilling.InAppBillingImplementation+InAppBillingServiceConnection.OnServiceConnected (Android.Content.ComponentName name, Android.OS.IBinder service) [0x00033] in <dc8bf25b40af44ada99053dbb7431c30>:0 
  at Android.Content.IServiceConnectionInvoker.n_OnServiceConnected_Landroid_content_ComponentName_Landroid_os_IBinder_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_name, System.IntPtr native_service) [0x00017] in <fb3979555cbc4c178444b284242e6fbe>:0 
  at (wrapper dynamic-method) System.Object:e422cf66-676d-4c5b-a484-486933c57518 (intptr,intptr,intptr,intptr)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants