question

jpotts avatar image
jpotts asked

NullReferenceException: Object reference not set to an instance of an object.

at PlayFab.Json.PocoJsonSerializerStrategy.DeserializeObject (System.Object value, System.Type type)

While running on iOS 12.2 on an iPhone XR using Unity 2018.3.11 (IL2CPP) with PlayFab SDK 2.63.190312 using the following code:

var request = new LoginWithIOSDeviceIDRequest
                {
                    InfoRequestParameters = new GetPlayerCombinedInfoRequestParams { GetPlayerProfile = true, GetUserVirtualCurrency = true }
                };

PlayFabClientAPI.LoginWithIOSDeviceID(request, r => OnSuccess(r), e => OnError(e));
2 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.

jpotts avatar image jpotts commented ·

Appears the issue is related to IL2CPP stripping. When stripping is set to Medium or High this issue occurs, on Low it does not. This tells me there is something missing from the link.xml file in the PlayFab SDK.

0 Likes 0 ·
jpotts avatar image jpotts commented ·

So, I changed my stripping level from High to Low and the issue went away. This tells me there's something missing from the link.xml file in the PlayFab SDK. Any advice?

0 Likes 0 ·
JayZuo avatar image
JayZuo answered

According to Unity's documentation, in Low Stripping Level, assemblies with types referenced in a sceneall and public types and members are marked. However, in Medium Stripping Level, they are not. PlayFab.Json used reflection for serialize/Deserialize, it's code might be stripped in Medium and High level. I'd think you can use the [Preserve] attribute in source code to prevent the UnityLinker from stripping that code. I didn't test this. But you can have a try. Hope this helps.

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

jpotts avatar image jpotts commented ·

I understand that. The problem is that the code being stripped is within the PlayFab SDK (the null reference exception happens when calling PlayFabClientAPI.LoginWithIOSDeviceID). I already tell the IL2CPP linker to not strip anything within my namespaces. Do I need to fix the PlayFab SDK myself?

0 Likes 0 ·
jpotts avatar image jpotts commented ·

I put in a pull request on the SDK to fix the issue:

https://github.com/PlayFab/UnitySDK/pull/211

0 Likes 0 ·
chaz32621 avatar image
chaz32621 answered

Checkout my post. It's an issue with unity3d and how playfab calls http requests. Should solve ur issue as well.

https://community.playfab.com/questions/27910/attempting-android-silent-login-sends-error-about.html?childToView=28042#comment-28042

10 |1200

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

jpotts avatar image
jpotts answered

To anyone else that has this issue, the solution is to add the following to the link.xml file inside of the PlayFabSDK folder:

<assembly fullname="Assembly-CSharp">
	<type fullname="PlayFab.*" preserve="all"/>
</assembly>
2 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.

jpotts avatar image jpotts commented ·
0 Likes 0 ·
Chris Kurhan avatar image Chris Kurhan commented ·

Even with after your PR was merged, with IL2CPP stripping of High (some people say medium as well) will result in this error. Make sure you have it on LOW

0 Likes 0 ·
Teemu Karjalainen avatar image
Teemu Karjalainen answered

Looking forward to an update on this. This prevents us from properly stripping our binaries.

10 |1200

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

Christopher Clogg avatar image
Christopher Clogg answered

I am also looking forward to an update. Even with the fix to link.xml, using code stripping of medium or high still has the same error it seems.

1 comment
10 |1200

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

Christopher Clogg avatar image Christopher Clogg commented ·

Note: I was able to fix it by adding [assembly: UnityEngine.Scripting.Preserve] near the top of the simplejson file in the Playfab SDK.

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.