Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

com.unity.purchasing: 3.1 ArgumentException: An item with the same key has already been added. Key

Discussion in 'Editor & General Support' started by matt_unity258, Jun 13, 2021.

  1. matt_unity258

    matt_unity258

    Joined:
    Dec 4, 2017
    Posts:
    17
    After Calling builder.AddProduct(string id, ProductType type, IDs storeIDs) with a bunch of products (with different ids) I get this exception (also with version 3.2) when I call UnityPurchasing.Initialize(this, builder);

    Code (CSharp):
    1. ArgumentException: An item with the same key has already been added. Key:
    2.   at System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) [0x00000] in <00000000000000000000000000000000>:0
    3.   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement] (System.Collections.Generic.IEnumerable`1[T] source, System.Func`2[T,TResult] keySelector, System.Func`2[T,TResult] elementSelector, System.Collections.Generic.IEqualityComparer`1[T] comparer) [0x00000] in <00000000000000000000000000000000>:0
    4.   at UnityEngine.Purchasing.ProductCollection.AddProducts (System.Collections.Generic.IEnumerable`1[T] products) [0x00000] in <00000000000000000000000000000000>:0
    5.   at UnityEngine.Purchasing.PurchasingManager.Initialize (UnityEngine.Purchasing.IInternalStoreListener listener, System.Collections.Generic.HashSet`1[T] products) [0x00000] in <00000000000000000000000000000000>:0
    6.   at System.Action`1[T].Invoke (T obj) [0x00000] in <00000000000000000000000000000000>:0
    I'm using Unity version 2020.3.11f1 and the same code I was using before I upgraded from unity Iap 2

    Any ideas what could be causing this? I don't see any place where I'm adding a duplicate key
    I see this happening on IOS right now but I'm pretty sure also on Android I'll check that soon
    TIA
     
  2. matt_unity258

    matt_unity258

    Joined:
    Dec 4, 2017
    Posts:
    17
    The store id was "" and because ProductColection has a Dictionary by storeId in it it was throwing this exception
     
    JeffDUnity3D likes this.