facebook / facebook-sdk-for-unity

The facebook sdk for unity.
https://developers.facebook.com/docs/unity
Other
489 stars 257 forks source link

NullReferenceException: Object reference not set to an instance of an object Facebook.Unity.MethodArguments.ToStringDict #188

Open kobyle69 opened 5 years ago

kobyle69 commented 5 years ago

Hi,

This is the Call Stack of above Exception:

NullReferenceException: Object reference not set to an instance of an object 
Facebook.Unity.MethodArguments.ToStringDict (System.Collections.Generic.IDictionary`2[TKey,TValue] dict) (at <fb73dac39b5a43b4b07fad75da5064da>:0) 
Facebook.Unity.MethodArguments.AddDictionary (System.String argumentName, System.Collections.Generic.IDictionary`2[TKey,TValue] dict) (at <fb73dac39b5a43b4b07fad75da5064da>:0) 
Facebook.Unity.Mobile.Android.AndroidFacebook.AppEventsLogEvent (System.String logEvent, System.Nullable`1[T] valueToSum, System.Collections.Generic.Dictionary`2[TKey,TValue] parameters) (at <fb73dac39b5a43b4b07fad75da5064da>:0) 
Facebook.Unity.FB.LogAppEvent (System.String logEvent, System.Nullable`1[T] valueToSum, System.Collections.Generic.Dictionary`2[TKey,TValue] parameters) (at <fb73dac39b5a43b4b07fad75da5064da>:0) 
AnalyticsManagerBase.LogEvent (System.String i_EventCategory, System.String i_EventAction, System.String i_EventLabel, System.Int64 i_Value) (at <3428ae3d9ccb42d28fef9d2e70986f86>:0) 

This is the code that caused it:

public virtual void LogEvent(string i_EventCategory, string i_EventAction, string i_EventLabel = "None", long i_Value = 0)
{            
    if (FB.IsInitialized)
    {
        FB.LogAppEvent(i_EventCategory, null, new Dictionary<string, object>() { { i_EventAction, i_EventLabel } });
    }
}

90% of the times, no exception is being raised, and I don't see how this code should cause such an exception.

Devices that this has happened on: Google Nexus 6 LG SP320 X Charge Motorola XT1789-05 Moto Z2 Force Motorola XT1635-01 Moto Z Play

iRDS commented 5 years ago

You must be passing into the parameters dictionary maybe a primitive nullable field like float? or bool? and not setting its value, which then causes the method ToDicString to fail, this was my case, just in case this helps out someone.

Tommigun1980 commented 1 week ago

6 years later this is still open. Yeah we can filter out nulls before sending the data but that's just unnecessary. Facebook any chance you could just add a null check here: https://github.com/facebook/facebook-sdk-for-unity/blob/8989abf45aabc803e846111df50c654883e542dc/Facebook.Unity/MethodArguments.cs#L111

Or has the Facebook SDK been completely abandoned?