Search Unity

Bug InvalidOperationException when receiving purchases

Discussion in 'Unity IAP' started by rvaleev, May 26, 2023.

  1. rvaleev

    rvaleev

    Joined:
    Apr 12, 2022
    Posts:
    1
    UnityIAP version: 4.7.0
    Error: InvalidOperationException: An attempt was made to transition a task to a final state when it had already completed.

    This error sometimes occurs for some players. After adding logs to the QueryPurchasesWithSkuType method in the GoogleQueryPurchasesService, it was discovered that there was a multiple call from the billing client.

    StackTrace:
    Code (CSharp):
    1.  
    2. System.Threading.Tasks.TaskCompletionSource`1[TResult].SetResult (TResult result) (at <00000000000000000000000000000000>:0)
    3. System.Action`2[T1,T2].Invoke (T1 arg1, T2 arg2) (at <00000000000000000000000000000000>:0)
    4. System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr,
    5. System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <00000000000000000000000000000000>:0)
    6. System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <00000000000000000000000000000000>:0)
    7. UnityEngine.AndroidJavaProxy.Invoke (System.String methodName, System.Object[] args) (at <00000000000000000000000000000000>:0)
    8. UnityEngine._AndroidJNIHelper.InvokeJavaProxyMethod (UnityEngine.AndroidJavaProxy proxy, System.IntPtr jmethodName, System.IntPtr jargs) (at <00000000000000000000000000000000>:0)
    9. Rethrow as TargetInvocationException: UnityEngine.Purchasing.GooglePurchasesResponseListener.onQueryPurchasesResponse(UnityEngine.AndroidJavaObject,UnityEngine.AndroidJavaObject) UnityEngine.AndroidJavaProxy.Invoke (System.String methodName, System.Object[] args) (at <00000000000000000000000000000000>:0)
    10. UnityEngine._AndroidJNIHelper.InvokeJavaProxyMethod (UnityEngine.AndroidJavaProxy proxy, System.IntPtr jmethodName, System.IntPtr jargs) (at <00000000000000000000000000000000>:0) UnityEngine.Debug:CallOverridenDebugHandler(Exception, Object)
    Client logs:

    ...
    [D 21.12.08.118 0:01.41.639] QueryPurchasesWithSkuType() skuType: subs
    [D 21.12.08.120 0:01.41.641] QueryPurchasesWithSkuType() skuType: inapp
    ...
    [D 21.12.36.632 0:02.10.153] QueryPurchasesWithSkuType() onQueryPurchaseResponse skuType: subs resultCode: ServiceTimeout purchases: 0
    [D 21.12.36.634 0:02.10.155] QueryPurchasesWithSkuType() onQueryPurchaseResponse skuType: inapp resultCode: ServiceTimeout purchases: 0
    ...
    [D 21.12.40.838 0:02.14.359] QueryPurchasesWithSkuType() onQueryPurchaseResponse skuType: inapp resultCode: ServiceDisconnected purchases: 0
    [D 21.12.40.838 0:02.14.359] QueryPurchasesWithSkuType() onQueryPurchaseResponse skuType: subs resultCode: ServiceDisconnected purchases: 0
    [E 21.12.40.922 0:02.14.443] InvalidOperationException: An attempt was made to transition a task to a final state when it had already completed.


    upload_2023-5-26_18-3-19.png
     
  2. BBO_Lagoon

    BBO_Lagoon

    Joined:
    Mar 2, 2017
    Posts:
    200
    I have a similar problem with iap package 4.9.4.

    Code (CSharp):
    1. InvalidOperationException
    2. UnityEngine.AndroidJavaProxy.Invoke (System.String methodName, System.Object[] args) (at <00000000000000000000000000000000>:0)
    3.  
    4. Managed Stack Trace:
    5.  
    6. System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <00000000000000000000000000000000>:0)
    7. System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <00000000000000000000000000000000>:0)
    8. UnityEngine.AndroidJavaProxy.Invoke (System.String methodName, System.Object[] args) (at <00000000000000000000000000000000>:0)
    9. UnityEngine._AndroidJNIHelper.InvokeJavaProxyMethod (UnityEngine.AndroidJavaProxy proxy, System.IntPtr jmethodName, System.IntPtr jargs) (at <00000000000000000000000000000000>:0)
    10. Rethrow as TargetInvocationException: UnityEngine.Purchasing.GooglePurchasesResponseListener.onQueryPurchasesResponse(UnityEngine.AndroidJavaObject,UnityEngine.AndroidJavaObject)
    11. UnityEngine.AndroidJavaProxy.Invoke (System.String methodName, System.Object[] args) (at <00000000000000000000000000000000>:0)
    12. UnityEngine._AndroidJNIHelper.InvokeJavaProxyMethod (UnityEngine.AndroidJavaProxy proxy, System.IntPtr jmethodName, System.IntPtr jargs) (at <00000000000000000000000000000000>:0)
     
  3. yenmoc

    yenmoc

    Joined:
    Sep 21, 2019
    Posts:
    6
    Any updates for this? Recently I discovered my game is still having the same problem

    image (11).png
     
  4. Bartt-Hypernova

    Bartt-Hypernova

    Joined:
    Feb 24, 2020
    Posts:
    8
    Oh, God, no... JNI issues in purchasing plugin? Again? Really? Really-really?
    Hey, Unitytech, what are you doing? How long will broken versions be released?

    Faced the same issue in Unity 2021.3.32 + Unity Purchasing v4.10
     
    bilck and Tommy-Angelo like this.
  5. tessellation

    tessellation

    Joined:
    Aug 11, 2015
    Posts:
    390
    Still happening with Unity Purchasing 4.10.0. Typically we're seeing this from users with an unstable internet connection or perhaps a corrupted Google Play Services installation.

    For example, in the logs we're seeing the Unity IAP billing system fails to find products (Reason: NoProductsAvailable) or Google Play Game Services fails to initialize.

    Seems to happen on a variety of devices and Android OS versions.
     
  6. ugurinal

    ugurinal

    Joined:
    Nov 25, 2019
    Posts:
    1
    I have the same issue with Unity Purchasing 4.10.0. and Unity 2022.3.18f1.
     
  7. ahmetteksas

    ahmetteksas

    Joined:
    Aug 19, 2021
    Posts:
    7
    Idiot unity developers !! same issue 4.10 version and they do not even think to solve this issue !
     
  8. Yannick_D

    Yannick_D

    Unity Technologies

    Joined:
    Feb 21, 2022
    Posts:
    235
    To give an update on this, we have multiple fixes coming soon with IAP 4.11.0 that should address this issue.