- Home /
PlayFab: KeyNotFoundException: The given key was not present in the dictionary.
I'm trying to set up a store in my game with PlayFab. I've set up all the items in a catalog called "Ships", and I have a virtual currency set up with the id "CC." When this code is ran, the player is logged in, and the code has already gotten all the proper info parameters.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PlayFab;
using PlayFab.ClientModels;
using PlayFab.Json;
public class PlayFabManager : MonoBehaviour
{
public Ship[] ships;
public void GetShipPrices()
{
GetCatalogItemsRequest request = new GetCatalogItemsRequest();
request.CatalogVersion = "Ships";
PlayFabClientAPI.GetCatalogItems(request, result =>
{
List<CatalogItem> shipsInStore = result.Catalog;
foreach (CatalogItem i in shipsInStore)
{
uint cost = i.VirtualCurrencyPrices["CC"];
Debug.Log(cost);
}
}, error => { });
}
}
When I call this method (after all the login stuff has happened), I keep getting this error:
KeyNotFoundException: The given key was not present in the dictionary. System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) (at :0) PlayFabManager+<>c.b_33_0 (PlayFab.ClientModels.GetCatalogItemsResult result) (at Assets/Scripts/PlayFabManager.cs:140) PlayFab.Internal.PlayFabHttp+<>c_DisplayClass19_0`1[TResult].<MakeApiCall>b1 () (at Assets/PlayFabSDK/Shared/Internal/PlayFabHttp/PlayFabHTTP.cs:215) PlayFab.Internal.PlayFabUnityHttp.OnResponse (System.String response, PlayFab.Internal.CallRequestContainer reqContainer) (at Assets/PlayFabSDK/Shared/Internal/PlayFabHttp/PlayFabUnityHttp.cs:201) UnityEngine.Debug:LogException(Exception) PlayFab.Internal.PlayFabUnityHttp:OnResponse(String, CallRequestContainer) (at Assets/PlayFabSDK/Shared/Internal/PlayFabHttp/PlayFabUnityHttp.cs:205) PlayFab.Internal.d_12:MoveNext() (at Assets/PlayFabSDK/Shared/Internal/PlayFabHttp/PlayFabUnityHttp.cs:153) UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
The PlayFabManager.cs:140 is at the "uint cost = i.VirtualCurrencyPrices["CC"];" line. I have no idea why, I've searched all over the PlayFab documentation and can't figure out what I'm doing wrong.. any ideas?