Facebook SDK assembly cannot be loaded

After updating to Unity 4.6 the Facebook SDK is not working anymore due to assembly authorization errors, see below. Does anybody know how to get this running again?

Unable to verify assembly data; you must provide an authorization key when loading this assembly.
UnityEngine.Security:LoadAndVerifyAssembly(Byte[])
<LoadFacebookClass>c__Iterator12:MoveNext() (at Assets/Facebook/Scripts/FB.cs:422)

Could not securely load assembly from https://integrated-plugin-canvas-rsrc.fbsbx.com/rsrc/unity/lib/sdk_6.0/CanvasFacebook.dll
UnityEngine.Debug:LogError(Object)
FbDebug:Error(String)
<LoadFacebookClass>c__Iterator12:MoveNext() (at Assets/Facebook/Scripts/FB.cs:426)

can you raise a bug about this, it seems like something needs to be updated by us or facebook.

Its a pretty easy fix. The Facebook SDK runs a check to see if its in Unity 4.5, as 4.5 introduced new security features for loading assemblies. If you remove the pre-processor directive for compiling in 4.5 then it works fine. I suppose you could also change it to #if Unity_4_6. But that will break again next time you upgrade.

Edit: Tried to post the solution here but haven’t yet got the hang of formatting code on the forums. Link goes to a nice looking UA solution.

9 Likes

Worked for me, just edit the FB.cs script and look for #if Unity_4_5. Then change it to #if Unity_4_6. Simple. :slight_smile:

3 Likes

Thanks man it worked for me… Althoughhhhh it works on my comp now but once uploaded to my phone nothing happens when i click the FB button i don’t get why it works on my comp but not on my android device!! Arrrr please help

would it happen to have something with this notice…
Game scripts or other custom code contains OnMouse_ event handlers. Presence of such handlers might impact performance on handheld devices.
UnityEditor.BuildPlayerWindow:BuildPlayerAndRun()

@Kiwasi
Man, you are to a saved-the-christmas level right now <3
Thank you SO MUCH!

1 Like

Awesome @Kiwasi

This happened to me while using FB SDK 6.2.2 and Unity 5.1.0f3. Had to change the file FB.cs from

#if UNITY_4_5 || UNITY_4_6 || UNITY_5_0 ||

to

#if UNITY_4_5 || UNITY_4_6 || UNITY_5_0 || UNITY_5

and then it worked.

3 Likes

If you are not going to go back to older versions with the project its better to just remove the pre-processor code. Entirely delete the code for the older version, and remove the pre-processor directives around the new code. That way you don’t need to keep making changes every time there is a point update.

You Awsome :slight_smile:

Thanks man,
I have unity 5.1 but it was not mention in FB.cs, so i added it in last like this

#if !UNITY_WINRT
            #if UNITY_4_5 || UNITY_4_6 || UNITY_5_0|| UNITY_5_0 || UNITY_5_1

Thanks for the tip!