question

tufanuyguner avatar image
tufanuyguner asked

PlayFab JSON Deserializer breaks on WebGL

Hello, I'm having trouble getting WebGL builds to work. It throws NullRef after LoginWithCustomID request, this never happens in Editor.

This is the error I'm getting:

NullReferenceException: Object reference not set to an instance of an object.
  at PlayFab.Json.PocoJsonSerializerStrategy.DeserializeObject (System.Object value, System.Type type) [0x00000] in <00000000000000000000000000000000>:0 
  at PlayFab.Json.SimpleJsonInstance+PlayFabSimpleJsonCuztomization.DeserializeObject (System.Object value, System.Type type) [0x00000] in <00000000000000000000000000000000>:0 
  at PlayFab.Json.PlayFabSimpleJson.DeserializeObject (System.String json, System.Type type, PlayFab.Json.IJsonSerializerStrategy jsonSerializerStrategy) [0x00000] in <00000000000000000000000000000000>:0 
  at PlayFab.Json.PlayFabSimpleJson.DeserializeObject[T] (System.String json, PlayFab.Json.IJsonSerializerStrategy jsonSerializerStrategy) [0x00000] in <00000000000000000000000000000000>:0 
  at PlayFab.Json.SimpleJsonInstance.DeserializeObject[T] (System.String json) [0x00000] in <00000000000000000000000000000000>:0 
  at PlayFab.Internal.PlayFabUnityHttp.OnResponse (System.String response, PlayFab.Internal.CallRequestContainer reqContainer) [0x00000] in <00000000000000000000000000000000>:0 
  at PlayFab.Internal.PlayFabUnityHttp+<Post>d__12.MoveNext () [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) [0x00000] in <00000000000000000000000000000000>:0 
UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object)
UnityEngine.DebugLogHandler:LogException(Exception, Object)
UnityEngine.Logger:LogException(Exception, Object)
UnityEngine.Debug:LogException(Exception)
PlayFab.Internal.PlayFabUnityHttp:OnResponse(String, CallRequestContainer)
PlayFab.Internal.<Post>d__12:MoveNext()
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
(Filename: currently not available on il2cpp Line: -1)

This is the API response

<id>.playfabapi.com/Client/LoginWithCustomID?sdk=UnitySDK-2.113.210830 Response:

{"code":200,"status":"OK","data":{"SessionTicket":"E04D539DD8494332--A22A7CAE63D64F6B-18AC3-8D98325FACBD8DF-EWWAGcSyR53S1LL+jCABjN77KCvGwzobizxFuWSevDg=","PlayFabId":"E04D539DD8494332","NewlyCreated":true,"SettingsForUser":{"NeedsAttribution":false,"GatherDeviceInfo":true,"GatherFocusInfo":true},"EntityToken":{"EntityToken":"NHxGUDIycHFHZTlYSG1sbzhCVTVjOWxTYUdNYWROUktjM2hXTUFxdmpoUjI0PXx7ImkiOiIyMDIxLTA5LTI5VDA4OjQ4OjU5LjQzMjc3NzVaIiwiaWRwIjoiQ3VzdG9tIiwiZSI6IjIwMjEtMDktMzBUMDg6NDg6NTkuNDMyNzc3NVoiLCJpZGkiOiJjZjIwYTA0Ny1iMWU3LTRjNmYtYWVmYi01ZTZiMGIwYTBmNWUiLCJoIjoiREQxQjI0QzMzM0Q5NDBEQiIsImVjIjoidGl0bGVfcGxheWVyX2FjY291bnQhRUI4N0ZBMENEOTdENTEwNi8xOEFDMy9FMDRENTM5REQ4NDk0MzMyL0NCNjUwRUQ3NkYzM0M1REMvIiwiZWkiOiJDQjY1MEVENzZGMzNDNURDIiwiZXQiOiJ0aXRsZV9wbGF5ZXJfYWNjb3VudCJ9","TokenExpiration":"2021-09-30T08:48:59.432Z","Entity":{"Id":"CB650ED76F33C5DC","Type":"title_player_account","TypeString":"title_player_account"}},"TreatmentAssignment":{"Variants":[],"Variables":[]}}}
sdkssupport
10 |1200

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

Gosen Gao avatar image
Gosen Gao answered

First, the PlayFabSimpleJson has been replaced by PlayFab.PluginManager.GetPlugin<ISerializerPlugin>(PluginContract.PlayFab_Serializer), you may try it to see if this issue still happens. For more information, please refer to https://community.playfab.com/questions/24205/json-parsing-issues.html.

“Object reference not set to an instance of an object” is a general error which is often caused by something missing. I can’t reproduce this issue, can you figure out in which step does this error occur?

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.

tufanuyguner avatar image tufanuyguner commented ·

Hi, I haven't changed the default serializer plugin, but PlayFab.PluginManager.GetPlugin<ISerializerPlugin>(PluginContract.PlayFab_Serializer) returns SimpleJson

plugin = this.CreatePlugin<PlayFab.Json.SimpleJsonInstance>();

It only happens in Windows and WebGL builds and never in editor. It might be happening in other builds as well but I haven't tried them yet. Both IL and Mono backends has this issue.

Here's the line that throws the null reference:

Assets\PlayFabSDK\Shared\Internal\SimpleJson.cs:1468

and here's what I do to get the NullReference

PlayFabClientAPI.LoginWithCustomID(new LoginWithCustomIDRequest { CreateAccount = true, CustomId = Guid.NewGuid().ToString() },OnLoginSuccess, OnPlayFabError);
0 Likes 0 ·
Gosen Gao avatar image Gosen Gao tufanuyguner commented ·

I didn’t see anything about SimpleJson in your LoginWithCustomID call. So I can’t reproduce this issue. Would you mind providing us some detailed code on how and where you are using SimpleJson for further research?

0 Likes 0 ·
tufanuyguner avatar image tufanuyguner Gosen Gao commented ·

I'm not using PlayFab's JSON stuff anywhere, PlayFab uses it internally to deserialize API responses.

0 Likes 0 ·
Show more comments
Niall Muldoon avatar image
Niall Muldoon answered

Old thread, but it does show up on google...

This is usually caused by stripping and I see it on iOS quite a bit. You can make use of the link.xml file to preserve a class that is being stripped, but I have also seen it where I've done this and the constructor is still being stripped, adding the [Serializable] tag prevents that.

https://docs.unity3d.com/Manual/ManagedCodeStripping.html#LinkXMLAnnotation

Example link.xml file:

 <assembly fullname="Assembly-CSharp">
     <type fullname="Namespace.ClassName" preserve="all"/>
 </assembly>
 <assembly fullname="PlayFab" preserve="all"/>
10 |1200

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

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.