question

chaz32621 avatar image
chaz32621 asked

Attempting Android Silent Login sends error about nullreferenceexception

Keep seeing this error everytime I attempt to login with a silent login on Android. Works fine in the editor.

NullReferenceException: Object reference not set to an instance of an object
03-22 22:43:08.881 8174 8248 E Unity : at PlayFab.Json.PocoJsonSerializerStrategy.DeserializeObject (System.Object value, System.Type type) [0x003c1] in <ed94fec7e53e476c931bca8bd186b365>:0
03-22 22:43:08.881 8174 8248 E Unity : at PlayFab.Json.SimpleJsonInstance+PlayFabSimpleJsonCuztomization.DeserializeObject (System.Object value, System.Type type) [0x0000a] in <ed94fec7e53e476c931bca8bd186b365>:0
03-22 22:43:08.881 8174 8248 E Unity : at PlayFab.Json.PlayFabSimpleJson.DeserializeObject (System.String json, System.Type type, PlayFab.Json.IJsonSerializerStrategy jsonSerializerStrategy) [0x0002d] in <ed94fec7e53e476c931bca8bd186b365>:0
03-22 22:43:08.881 8174 8248 E Unity : at PlayFab.Json.PlayFabSimpleJson.DeserializeObject[T] (System.String json, PlayFab.Json.IJsonSerializerStrategy jsonSerializerStrategy) [0x00000] in <ed94fec7e53e476c931bca8bd186b365>:0
03-22 22:43:08.881 8174 8248 E Unity : at PlayFab.Json.SimpleJsonInstance.DeserializeObject[T] (System.String json) [0x00000] in <ed94fec7e53e476c931bca8bd186b365>:0
03-22 22:43:08.881 8174 8248 E Unity : at PlayFab.Internal.PlayFabUnityHttp.OnResponse (System.String response, PlayFab.Interna

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

Andy avatar image Andy ♦♦ commented ·

Can you confirm which version of Unity and which version of the PlayFab plugin you're using?

1 Like 1 ·
Andy avatar image Andy ♦♦ Andy ♦♦ commented ·

Also, a fiddler trace might be useful to help understand what kind of response payload you're getting back from the request.

1 Like 1 ·
chaz32621 avatar image chaz32621 Andy ♦♦ commented ·

Fiddle trace?

I see this might be the issue with it to be honest. I get this debug code. Then the error is thrown.

public void SilentlyAuthenticate(System.Action<LoginResult> callback = null)
{
#if UNITY_ANDROID && !UNITY_EDITOR

//Get the device id from native android

AndroidJavaClass up = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = up.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject contentResolver = currentActivity.Call<AndroidJavaObject>("getContentResolver");
AndroidJavaClass secure = new AndroidJavaClass("android.provider.Settings$Secure");
string deviceId = secure.CallStatic<string>("getString", contentResolver, "android_id");
Debug.Log("Android Silent Login");
//Login with the android device ID

it might be the DeviceIDRequest. It works fine in Unity Editor tho.

0 Likes 0 ·
chaz32621 avatar image chaz32621 Andy ♦♦ commented ·

I am using Unity2019.2. I guess I should ask is it compatible with that? Lol. Also latest playfab build. I like to be ahead on everything, completly updated.

0 Likes 0 ·
chaz32621 avatar image
chaz32621 answered

Found the problem.

In the OnResponse() I changed.

var serializer = PluginManager.GetPlugin<ISerializerPlugin>(PluginContract.PlayFab_Serializer);
var httpResult = serializer.DeserializeObject<HttpResponseObject>(response);

too

var serializer = PluginManager.GetPlugin<ISerializerPlugin>(PluginContract.PlayFab_Serializer);
HttpResponseObject httpResult = new HttpResponseObject();
httpResult = JsonWrapper.DeserializeObject<HttpResponseObject>(response);

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.

chaz32621 avatar image chaz32621 commented ·

So back on 2018.2 :)

0 Likes 0 ·
chaz32621 avatar image chaz32621 commented ·

Using Unity2019.2 again :)

0 Likes 0 ·
Thomas Brown avatar image Thomas Brown commented ·

Thanks for this! Just wanted to give some context to others on why this is likely working. il2cpp was likely stripping away his HttpResponseObject on build because the class constructor wasn't called so it though it wasn't being used.

Another way to solve this would be to continue doing things the first way but defining a link.xml file.

0 Likes 0 ·
Andy avatar image
Andy answered

A fiddler trace is a network capture using a tool called Fiddler. It's useful for debugging anything related to http requests (which all of our APIs are).

We haven't tested with Unity 2019.2, so there's a chance there's a new incompatibility that's been introduced in the latest engine.

The most likely reason for the null reference exception in the JSON deserializer is that the login request returned invalid JSON, maybe because the HTTP system isn't working properly.

Can you confirm you've selected UnityWebRequest as the Request Type in the PlayFab Extension?

Are you able to debug the game as it's running? If so, can you set a breakpoint on PlayFab.Internal.PlayFabUnityHttp.OnResponse and observe the response string? That might tell us more about what's going on.

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.

chaz32621 avatar image chaz32621 commented ·

Looks to be an Unity3d 2019.2 issue with Playfab. Unity2019.1 works fine however. Guess we will see a fix for this later in the year?

It also looks like it sends an empty request. Fiddler and Charles never send a request at all. I will downgrade to 2019.1 luckly I have a backup project at the moment.

0 Likes 0 ·
tesla avatar image
tesla answered

Same error here. Login in Editor and Ios is working but fails in Android. I get exception at

PlayFab.Json.PocoJsonSerializerStrategy.DeserializeObject

This is the call I make:

var request = new LoginWithAndroidDeviceIDRequest
{
    AndroidDevice = SystemInfo.deviceModel,
    AndroidDeviceId = Utility.GetDeviceId(),
    CreateAccount = true
};


PlayFabClientAPI.LoginWithAndroidDeviceID(request, OnLoginSuccess, OnLoginFailure);

And I get this exception upon the response. The callback methods are never called because of the exception. I guess this has nothing to do with Fiddler check, because the login method works on IOS.

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[T] (System.String json, PlayFab.Json.IJsonSerializerStrategy jsonSerializerStrategy) [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 
PlayFab.Internal.<Post>d__12:MoveNext()
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
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.

tesla avatar image tesla commented ·

Ok. Found the problem for myself. This was happening because of the IL2Cpp stripping setting. Under the Optimization part, I Changed "Managed Stripping Level" = "Low" . It was "Medium" before.

1 Like 1 ·

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.