question

Rizwan Babar avatar image
Rizwan Babar asked

KeyNotFoundException: The given key was not present in the dictionary.

This is my code which works perfectly. When I add one more entry into title data like data.Add(GemsKey, "2"); It gives error: KeyNotFoundException: The given key was not present in the dictionary.

But if I replace one of existing entries with data.Add(GemsKey, "2"); It works fine too. Can anybody tell me whats the exact issue ? P.s: I'm using it on Unity3D...

    public static Dictionary<string, string> InitialUserData(bool fb)
    {
        Dictionary<string, string> data = new Dictionary<string, string>();
        data.Add(TotalEarningsKey, "0");
        data.Add(ChatsKey, "");
        data.Add(EmojiKey, "");
        if (fb)
        {
            data.Add(CoinsKey, StaticStrings.initCoinsCountFacebook.ToString());
            data.Add(AvatarIndexKey, "fb");
        }
        else
        {
            data.Add(CoinsKey, StaticStrings.initCoinsCountGuest.ToString());
            data.Add(AvatarIndexKey, "0");
        }


        data.Add(GamesPlayedKey, "0");
        data.Add(TwoPlayerWinsKey, "0");
        data.Add(FourPlayerWinsKey, "0");


        data.Add(TitleFirstLoginKey, "1");
        data.Add(FortuneWheelLastFreeKey, DateTime.Now.Ticks.ToString());
        return data;
    }
Player DataAccount ManagementdataTitle Data
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Citrus Yan avatar image
Citrus Yan answered

The code looks alright, could you please share the complete error log and some reproduce steps for us to investigate?

4 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Rizwan Babar avatar image Rizwan Babar commented ·

I get 2 errors basically.

Data updated error Invalid input parameters
UnityEngine.Debug:Log(Object)
MyPlayerData:<UpdateUserData>m__1(PlayFabError) (at Assets/Ludo Masters/Scripts/MyPlayerData.cs:171)
System.Delegate:DynamicInvoke(Object[])
PlayFab.Internal.ResultContainer`1:WrapCallback(Delegate, Object) (at Assets/PlayFabSDK/Internal/ResultContainer.cs:105)
PlayFab.Internal.ResultContainer`1:HandleResults(CallRequestContainer, Delegate, ErrorCallback, Action`2) (at Assets/PlayFabSDK/Internal/ResultContainer.cs:92)
PlayFab.<UpdateUserData>c__AnonStorey35:<>m__0(CallRequestContainer) (at Assets/PlayFabSDK/Public/PlayFabClientAPI.cs:1145)
PlayFab.CallRequestContainer:InvokeCallback() (at Assets/Plugins/PlayFabShared/PlayFabErrors.cs:282)
PlayFab.Internal.<MakeRequestViaUnity>c__Iterator0:MoveNext() (at Assets/PlayFabSDK/Internal/PlayFabHTTP.cs:285)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
0 Likes 0 ·
Rizwan Babar avatar image Rizwan Babar commented ·

error.txt

This is the other error. It was long so I had to put it in text file. The first one comes as debug log message and this one as error.

0 Likes 0 ·
error.txt (2.8 KiB)
Rizwan Babar avatar image Rizwan Babar commented ·

Ok so, After further research I found that there is limit of data update in one request. Any solution to this?

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan Rizwan Babar commented ·

For the "Invalid input parameters" error, there should always be an errorDetails returned with any error message from our service. Can you check to see what it is? And, based on your description, looks like this error derives from exceeding the limit of data update, which is 10, if that's the case, you may want to consider splitting the data in multiple calls or contact the sales team for more quota.

For the KeyNotFound Exception, can you share some reproduce steps showing the operations you performed on the dictionary, which led to the KeyNotFound Exception? By the way, I found these threads from the Unity forum you may find helpful:

Best way to get infos about KeyNotFoundException: The given key was not present in the dictionary.

KeyNotFoundException: The given key was not present in the dictionary. (UNET)

KeyNotFoundException: The given key was not present in the dictionary.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Error rendering WebPanel (widgets/consolidation-widget.ftl): org.hibernate.hql.internal.ast.QuerySyntaxException: AvailableConsolidation is not mapped [from AvailableConsolidation up where up.node = :node]