question

voxelentmt avatar image
voxelentmt asked

NullReferenceException when making a requests regarding user data

Making the following requests generates a null reference exception in the Playfab code:

string gender = "somevalue";
string birthday = "somevalue";
var req = new UpdateUserDataRequest
        {
            Data =
            {
                { "gender", gender },
                { "birthday", birthday }
            }
        };
        PlayFabClientAPI.UpdateUserData(req, OnUserDataUpdated, OnRegisterFailure);

And trying to fetch the data (after logging in) also generates an error:

PlayFabClientAPI.GetUserData(new GetUserDataRequest
        {
            Keys = {
                "gender",
                "birthday"
            }
        }, OnGetUserData, OnPlayfabError);

Error:

NullReferenceException: Object reference not set to an instance of an object
MapUI.OnGetAccountInfo (PlayFab.ClientModels.GetAccountInfoResult result) (at Assets/UI/Scripts/MapUI.cs:135)
PlayFab.Internal.PlayFabHttp+<>c__DisplayClass23_0`1[TResult].<_MakeApiCall>b__1 () (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:247)
UnityEngine.Debug:LogException(Exception)
PlayFab.Internal.PlayFabUnityHttp:OnResponse(String, CallRequestContainer) (at Assets/PlayFabSDK/Shared/Internal/PlayFabHttp/PlayFabUnityHttp.cs:251)
PlayFab.Internal.<Post>d__12:MoveNext() (at Assets/PlayFabSDK/Shared/Internal/PlayFabHttp/PlayFabUnityHttp.cs:198)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr) (at /Users/builduser/buildslave/unity/build/Runtime/Export/Scripting/Coroutines.cs:17)

I am using Unity 2019.4.0f1 and the latest version of the Playfab SDK (2.102.210111).

Other requests seem to work except for these two regarding user data.

Player Dataunity3ddata
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

From the error stack I can see that NullReferenceException happens at:

MapUI.OnGetAccountInfo (PlayFab.ClientModels.GetAccountInfoResult result) (at Assets/UI/Scripts/MapUI.cs:135)

which is not related to the code you provided.

Could you please share the code snippet of "MapUI.OnGetAccountInfo" ?

3 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.

voxelentmt avatar image voxelentmt commented ·

The line 135 is the function call of the request, my code looks like this:

// line 130
private void OnGetAccountInfo(GetAccountInfoResult result) { string username = result.AccountInfo.Username; usernameText.SetText(username); // line 135 PlayFabClientAPI.GetUserData(new GetUserDataRequest { Keys = { "gender", "birthday" } }, OnGetUserData, OnPlayfabError); }
0 Likes 0 ·
Citrus Yan avatar image Citrus Yan voxelentmt commented ·

The "Keys" field is a list of strings:

List<string> 

Please use the following statement to initialize it:

Keys = new List<string> { "gender", "birthday" }
0 Likes 0 ·
voxelentmt avatar image voxelentmt Citrus Yan commented ·

That fixed it.. Weird that it compiled if it was wrong

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.