On Android, receipt validation always fails and I get this exception System.NullReferenceException(Object reference not set to an instance of an object.). On iOS, I think receipt validation never fails but I sometimes get the same exception System.NullReferenceException(Object reference not set to an instance of an object.).
My device is logged in and uses LoginWithAndroidDevice/LoginWithIOSDevice.
The variables PurchaseditemCurrencyCode, PurchaseditemPurchasePrice, SignedData and Signature are not null and I think that they have the correct values because I can see in my Google Play account that the in-app product purchase is successful, but in the PlayFab Game Manager receipt validation fails.
My values on Android: PurchaseditemCurrencyCode = "EUR", PurchaseditemPurchasePrice = 229, SignedData = "{\"orderId\":..." and Signature = "eMU3xCYDD4L..."
My values on iOS: PurchaseditemCurrencyCode = "EUR", PurchaseditemPurchasePrice = 229, SignedData = "MllVSAYJK..."
I don't know why I'm getting this exception. Am I using the PlayFab API calls correctly or am I doing something wrong?
My Android and iOS code:
if (purchaseIsSuccessful == true) { try { if (Device.RuntimePlatform == Device.iOS) { if (productId == "Consumable11") await DoValidateIOSReceiptAsync(PurchaseditemCurrencyCode, PurchaseditemPurchasePrice, SignedData); } else { if (Device.RuntimePlatform == Device.Android) { if (productId == "Consumable11") await DoValidateAndroidReceiptAsync(PurchaseditemCurrencyCode, PurchaseditemPurchasePrice, SignedData, Signature); } } } catch (Exception ex) { ExceptionMessage1 = ex.Message.ToString(); ExceptionMessage2 = ex.ToString(); } } public async Task DoValidateAndroidReceiptAsync(string purchaseditemcurrencycode, int purchaseditempurchaseprice, string signeddata, string signature) { await ValidateAndroidReceiptAsync(purchaseditemcurrencycode, purchaseditempurchaseprice, signeddata, signature); } private async Task ValidateAndroidReceiptAsync(string purchaseditemcurrencycode, int purchaseditempurchaseprice, string signeddata, string signature) { var result = await PlayFabClientAPI.ValidateGooglePlayPurchaseAsync(new ValidateGooglePlayPurchaseRequest() { CurrencyCode = purchaseditemcurrencycode, PurchasePrice = (uint)purchaseditempurchaseprice, ReceiptJson = signeddata, Signature = signature }); if (result.Error != null) PlayFabMessage = "not successful"); else PlayFabMessage = "successful"); } public async Task DoValidateIOSReceiptAsync(string purchaseditemcurrencycode, int purchaseditempurchaseprice, string signeddata) { await ValidateIOSReceiptAsync(purchaseditemcurrencycode, purchaseditempurchaseprice, signeddata); } private async Task ValidateIOSReceiptAsync(string purchaseditemcurrencycode, int purchaseditempurchaseprice, string signeddata) { var result = await PlayFabClientAPI.ValidateIOSReceiptAsync(new ValidateIOSReceiptRequest() { CurrencyCode = purchaseditemcurrencycode, PurchasePrice = purchaseditempurchaseprice, ReceiptData = signeddata }); if (result.Error != null) PlayFabMessage = "not successful"); else PlayFabMessage = "successful"); }
UPDATE:
I use the following code to get more informations about the exception.
catch (NullReferenceException ex) { Crashes.TrackError(ex); }
And here is what I got in App Center:
iOS Json:
{ "length": 0, "offset": 0, "id": "71aef385-bb48-44d7-b59d-a53368c72c66", "exception": { "type": "System.NullReferenceException", "message": "Object reference not set to an instance of an object", "stackTrace": " at InapppurchaseTest.iOS.Game1.ValidateIOSReceiptAsync (System.String purchaseditemcurrencycode, System.Int32 purchaseditempurchaseprice, System.String signeddata, System.String signature) <0x1047fa730 + 0x002dc> in <f7cd0204315c470baa0e7963fe272e8d#b28b8328fb987f6bc8a6ed35dda86f7b>:0 \n at InapppurchaseTest.iOS.Game1.DoValidateIOSReceiptAsync (System.String purchaseditemcurrencycode, System.Int32 purchaseditempurchaseprice, System.String signeddata, System.String signature) <0x1047fa4e0 + 0x00183> in <f7cd0204315c470baa0e7963fe272e8d#b28b8328fb987f6bc8a6ed35dda86f7b>:0 \n at InapppurchaseTest.iOS.Game1.CheckPurchase (System.String productId) <0x1047f7a00 + 0x0041f> in <f7cd0204315c470baa0e7963fe272e8d#b28b8328fb987f6bc8a6ed35dda86f7b>:0 ", "wrapperSdkName": "appcenter.xamarin" }, "appId": "d91b27bb-6d85-406b-87be-e7d17c3e391e", "installId": "F8765F5D-9FD1-4113-BA5C-97116E8A9693", "isTestMessage": false, "timestamp": "2019-07-04T18:12:48.637Z", "sid": "b6f64559-aec0-4fef-b0be-c3290bc8dba0", "device": { "sdkName": "appcenter.ios", "sdkVersion": "2.1.0", "wrapperSdkVersion": "2.1.1", "wrapperSdkName": "appcenter.xamarin", "model": "iPhone9,3", "oemName": "Apple", "osName": "iOS", "osVersion": "12.3.1", "osBuild": "16F203", "locale": "de_LU", "timeZoneOffset": 120, "screenSize": "1334x750", "appVersion": "22.0.0", "carrierName": "Orange Luxembourg", "carrierCountry": "lu", "appBuild": "22.0.0", "appNamespace": "project.MonoGame.InapppurchaseTestNew.iOS", "wrapperRuntimeVersion": "11.14.0" } }
Android Json:
{ "length": 0, "offset": 0, "id": "63783019-f17b-47e1-8865-4e6290f43fbd", "exception": { "type": "System.NullReferenceException", "message": "Object reference not set to an instance of an object", "stackTrace": " at ggdgdgd.Android.Game1.ValidateAndroidReceiptAsync (System.String purchaseditemcurrencycode, System.Int32 purchaseditempurchaseprice, System.String signeddata, System.String signature) [0x000c3] in <11446e8c56cb4e78a270889c3b890601>:0 \n at ggdgdgd.Android.Game1.DoValidateAndroidReceiptAsync (System.String purchaseditemcurrencycode, System.Int32 purchaseditempurchaseprice, System.String signeddata, System.String signature) [0x0007a] in <11446e8c56cb4e78a270889c3b890601>:0 \n at ggdgdgd.Android.Game1.CheckPurchase (System.String productId) [0x0030a] in <11446e8c56cb4e78a270889c3b890601>:0 ", "wrapperSdkName": "appcenter.xamarin" }, "appId": "9a9708c4-af57-452a-8751-53e06bb4544c", "installId": "6700532c-571e-4afe-bc4f-0273bfd8674c", "isTestMessage": false, "timestamp": "2019-07-04T17:42:35.861Z", "sid": "50ec5b4f-11b5-48d3-b653-6528eb796b8d", "device": { "sdkName": "appcenter.android", "sdkVersion": "2.1.0", "wrapperSdkVersion": "2.1.1", "wrapperSdkName": "appcenter.xamarin", "model": "SM-P600", "oemName": "samsung", "osName": "Android", "osVersion": "5.1.1", "osBuild": "LMY47X", "osApiLevel": 22, "locale": "de_DE", "timeZoneOffset": 120, "screenSize": "2560x1600", "appVersion": "22.0", "appBuild": "22", "appNamespace": "com.test.GetinapppurchaseAndroidneu", "wrapperRuntimeVersion": "9.3.0.23" } }
Will this help to find the problem?