Skip to main content
added full error and stack trace
Source Link
Stefan
  • 117
  • 1
  • 11

Full stack trace:

InvalidOperationException: Collection was modified; enumeration operation may not execute.
System.ThrowHelper.ThrowInvalidOperationException (System.ExceptionResource resource) (at <9577ac7a62ef43179789031239ba8798>:0)
System.Collections.Generic.List`1+Enumerator[T].MoveNextRare () (at <9577ac7a62ef43179789031239ba8798>:0)
System.Collections.Generic.List`1+Enumerator[T].MoveNext () (at <9577ac7a62ef43179789031239ba8798>:0)
UnityEngine.Purchasing.CodelessIAPStoreListener.ProcessPurchase (UnityEngine.Purchasing.PurchaseEventArgs e) (at Assets/Plugins/UnityPurchasing/script/CodelessIAPStoreListener.cs:175)
UnityEngine.Purchasing.StoreListenerProxy.ProcessPurchase (UnityEngine.Purchasing.PurchaseEventArgs e) (at Library/PackageCache/[email protected]/Runtime/managed/Purchasing/StoreListenerProxy.cs:34)
UnityEngine.Purchasing.PurchasingManager.ProcessPurchaseIfNew (UnityEngine.Purchasing.Product product) (at Library/PackageCache/[email protected]/Runtime/managed/Purchasing/PurchasingManager.cs:250)
UnityEngine.Purchasing.PurchasingManager.OnPurchaseSucceeded (System.String id, System.String receipt, System.String transactionId) (at Library/PackageCache/[email protected]/Runtime/managed/Purchasing/PurchasingManager.cs:112)
UnityEngine.Purchasing.JSONStore.OnPurchaseSucceeded (System.String id, System.String receipt, System.String transactionID) (at <828972e73f634ff790a93860533a30ad>:0)
UnityEngine.Purchasing.FakeStore.<>n__0 (System.String id, System.String receipt, System.String transactionID) (at <828972e73f634ff790a93860533a30ad>:0)
UnityEngine.Purchasing.FakeStore+<>c__DisplayClass15_0.<FakePurchase>b__0 (System.Boolean allow, UnityEngine.Purchasing.PurchaseFailureReason failureReason) (at <828972e73f634ff790a93860533a30ad>:0)
UnityEngine.Purchasing.UIFakeStore+<>c__DisplayClass14_0`1[T].<StartUI>b__0 (System.Boolean result, System.Int32 codeValue) (at <828972e73f634ff790a93860533a30ad>:0)
UnityEngine.Purchasing.UIFakeStore.OkayButtonClicked () (at <828972e73f634ff790a93860533a30ad>:0)
UnityEngine.Purchasing.UIFakeStore.<InstantiateDialog>b__16_1 () (at <828972e73f634ff790a93860533a30ad>:0)
UnityEngine.Events.InvokableCall.Invoke () (at /Users/bokken/buildslave/unity/build/Runtime/Export/UnityEvent/UnityEvent.cs:166)
UnityEngine.Events.UnityEvent.Invoke () (at /Users/bokken/buildslave/unity/build/Runtime/Export/UnityEvent/UnityEvent/UnityEvent_0.cs:58)
UnityEngine.UI.Button.Press () (at /Applications/Unity/Hub/Editor/2019.4.17f1/Unity.app/Contents/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/Button.cs:68)
UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at /Applications/Unity/Hub/Editor/2019.4.17f1/Unity.app/Contents/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/Button.cs:110)
UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at /Applications/Unity/Hub/Editor/2019.4.17f1/Unity.app/Contents/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/ExecuteEvents.cs:50)
UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at /Applications/Unity/Hub/Editor/2019.4.17f1/Unity.app/Contents/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/ExecuteEvents.cs:261)
UnityEngine.EventSystems.EventSystem:Update() (at /Applications/Unity/Hub/Editor/2019.4.17f1/Unity.app/Contents/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/EventSystem.cs:377)

I understand this issue would be caused if I were to iterate over a collection with something like a foreach and modifying/removing the elements over the iteration.

I understand this issue would be caused if I were to iterate over a collection with something like a foreach and modifying/removing the elements over the iteration.

Full stack trace:

InvalidOperationException: Collection was modified; enumeration operation may not execute.
System.ThrowHelper.ThrowInvalidOperationException (System.ExceptionResource resource) (at <9577ac7a62ef43179789031239ba8798>:0)
System.Collections.Generic.List`1+Enumerator[T].MoveNextRare () (at <9577ac7a62ef43179789031239ba8798>:0)
System.Collections.Generic.List`1+Enumerator[T].MoveNext () (at <9577ac7a62ef43179789031239ba8798>:0)
UnityEngine.Purchasing.CodelessIAPStoreListener.ProcessPurchase (UnityEngine.Purchasing.PurchaseEventArgs e) (at Assets/Plugins/UnityPurchasing/script/CodelessIAPStoreListener.cs:175)
UnityEngine.Purchasing.StoreListenerProxy.ProcessPurchase (UnityEngine.Purchasing.PurchaseEventArgs e) (at Library/PackageCache/[email protected]/Runtime/managed/Purchasing/StoreListenerProxy.cs:34)
UnityEngine.Purchasing.PurchasingManager.ProcessPurchaseIfNew (UnityEngine.Purchasing.Product product) (at Library/PackageCache/[email protected]/Runtime/managed/Purchasing/PurchasingManager.cs:250)
UnityEngine.Purchasing.PurchasingManager.OnPurchaseSucceeded (System.String id, System.String receipt, System.String transactionId) (at Library/PackageCache/[email protected]/Runtime/managed/Purchasing/PurchasingManager.cs:112)
UnityEngine.Purchasing.JSONStore.OnPurchaseSucceeded (System.String id, System.String receipt, System.String transactionID) (at <828972e73f634ff790a93860533a30ad>:0)
UnityEngine.Purchasing.FakeStore.<>n__0 (System.String id, System.String receipt, System.String transactionID) (at <828972e73f634ff790a93860533a30ad>:0)
UnityEngine.Purchasing.FakeStore+<>c__DisplayClass15_0.<FakePurchase>b__0 (System.Boolean allow, UnityEngine.Purchasing.PurchaseFailureReason failureReason) (at <828972e73f634ff790a93860533a30ad>:0)
UnityEngine.Purchasing.UIFakeStore+<>c__DisplayClass14_0`1[T].<StartUI>b__0 (System.Boolean result, System.Int32 codeValue) (at <828972e73f634ff790a93860533a30ad>:0)
UnityEngine.Purchasing.UIFakeStore.OkayButtonClicked () (at <828972e73f634ff790a93860533a30ad>:0)
UnityEngine.Purchasing.UIFakeStore.<InstantiateDialog>b__16_1 () (at <828972e73f634ff790a93860533a30ad>:0)
UnityEngine.Events.InvokableCall.Invoke () (at /Users/bokken/buildslave/unity/build/Runtime/Export/UnityEvent/UnityEvent.cs:166)
UnityEngine.Events.UnityEvent.Invoke () (at /Users/bokken/buildslave/unity/build/Runtime/Export/UnityEvent/UnityEvent/UnityEvent_0.cs:58)
UnityEngine.UI.Button.Press () (at /Applications/Unity/Hub/Editor/2019.4.17f1/Unity.app/Contents/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/Button.cs:68)
UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at /Applications/Unity/Hub/Editor/2019.4.17f1/Unity.app/Contents/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/Button.cs:110)
UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at /Applications/Unity/Hub/Editor/2019.4.17f1/Unity.app/Contents/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/ExecuteEvents.cs:50)
UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at /Applications/Unity/Hub/Editor/2019.4.17f1/Unity.app/Contents/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/ExecuteEvents.cs:261)
UnityEngine.EventSystems.EventSystem:Update() (at /Applications/Unity/Hub/Editor/2019.4.17f1/Unity.app/Contents/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/EventSystem.cs:377)

I understand this issue would be caused if I were to iterate over a collection with something like a foreach and modifying/removing the elements over the iteration.

Source Link
Stefan
  • 117
  • 1
  • 11

Unity IAP - Collection was modified; enumeration operation may not execute

In Unity, after importing UnityIAP Version: 2.3.0, I have a button to which I attached an IAP Button component like in the image below:

enter image description here

My SkinsPanel class looks like this:

using System.Collections.Generic;
using DG.Tweening;
using UnityEngine;
using UnityEngine.Purchasing;

public class SkinsPanel : MonoBehaviour
{
    [SerializeField] private RectTransform SorcererPurchaseButton; //reference to the button that is being pressed
    private string sorcererID = "com.company.test.sorcererID";

    public void OnPurchaseComplete(Product product)
    {
        if (product.definition.id == sorcererID)
        {
            SorcererPurchaseButton.gameObject.SetActive(false);
            //SorcererPurchaseButton.DOAnchorPos(new Vector2(1000, 1000), 0f);
        }
    }

    public void OnPurchaseFailed(Product product, PurchaseFailureReason failureReason)
    {
        Debug.Log("Failed");
    }
}

Nothing incredible complicated, a reference to the button and two functions: OnPurchaseComplete and OnPurchaseFailed.

Now, if the user completes the purchase succesfully:

enter image description here

I'm getting a Collection was modified; enumeration operation may not execute. error:

enter image description here

I understand this issue would be caused if I were to iterate over a collection with something like a foreach and modifying/removing the elements over the iteration.

If I were to to simply change the position of the button like:

//SorcererPurchaseButton.gameObject.SetActive(false);
SorcererPurchaseButton.DOAnchorPos(new Vector2(1000, 1000), 0f);

this would work without any issues.

What is the issue here? Is it some Unity IAP bug?