FacebookLogin not working with silverlight 4 using graph API in changeset 50970 Issue Found

Jun 2, 2010 at 1:47 PM

I also posted this in the Issue tracker but it seems more people frequent the discussions section.

I'm having issues with the new Graph Login within silverlight 4. I've written a little test application which is supposed to login and display the Facebook userid. I noticed the sample app is using

<%@ Register Assembly="System.Web.Silverlight" Namespace="System.Web.UI.SilverlightControls" TagPrefix="asp" %> 
which I have had to remove.
and
<asp:Silverlight ID="Silverlight1" runat="server" Source="~/ClientBin/FBToolkit.Sample.Silverlight.xap" MinimumVersion="3.0.40307.0" Width="100%" Height="100%" />

Which refers to the Silverlight 2 DLL. So I've had to replace it with 

<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
<param name="source" value="ClientBin/FaceBookSillverLightNewLoginTest.xap"/>
<param name="onError" value="onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="4.0.50401.0" />
<param name="autoUpgrade" value="true" />
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50401.0" style="text-decoration:none">
<img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
</a>
</object>

The problem is getting the new fblogin_graph.js file to communicate back to the Silverlight application. I've stepped through the Silverlight app and the problem seems to be occur in the following function.

function facebook_onlogin(session)
{
var plugin = document.getElementById(silverlightPluginId);
plugin.Content.FacebookLoginControl.LoggedIn(session.access_token, session.uid);


specifically the plugin.Content.FacebookLoginControl.LoggedIn(session.access_token, session.uid); doesn't fire an event back into the Silverlight application. I am also receiving the following exception in firebug under FireFox just after this line executes.

uncaught exception: System.InvalidOperationException: No compatible method found. at System.Windows.Browser.ManagedObjectInfo.ScriptMemberGroup.Invoke(ManagedObject obj, InvokeType invokeType, ScriptParam[] args) at System.Windows.Browser.ManagedObjectInfo.Invoke(ManagedObject obj, InvokeType invokeType, String memberName, ScriptParam[] args) at System.Windows.Hosting.ManagedHost.InvokeScriptableMember(IntPtr pHandle, Int32 nMemberID, Int32 nInvokeType, Int32 nArgCount, ScriptParam[] pArgs, ScriptParam& pResult, ExceptionInfo& pExcepInfo)

I'm thinking the scriptmanager isn't working correctly but cant seem to figure out why. 

I've attached my source code in a post under the Issue Tracker located here http://facebooktoolkit.codeplex.com/workitem/17876

Jun 2, 2010 at 3:53 PM
Edited Jun 2, 2010 at 3:55 PM

I've also tried using the FBToolkit.Sample.Silverlight.Web sample application. I had to reference a silverlight 2.0 dll (System.Web.Silverlight) and I changed the 

private const string ApplicationKey = "bbf2a1fe0ab6a691884fbe148b92721d";

private const string ApplicationSecret = "34135e7fb9d9ae4409367268e47ae052";

private const string ApplicationId = "115700911806381";

to ones under my account. The application is accessible at the following URL

http://apps.facebook.com/onezeriosixtest/

but I still have issues when the login button is clicked the login dialog shows up which is good but once I click login I recieve the following error

uncaught exception: System.ArgumentException: Invalid args for this operation. Parameter name: args at System.Windows.Hosting.ScriptingInterface.ConvertFromScriptParams(ParameterInfo[] parameters, ScriptParam[] args) at System.Windows.Browser.ManagedObjectInfo.ScriptMethod.Invoke(ManagedObject obj, InvokeType invokeType, ScriptParam[] args) at System.Windows.Browser.ManagedObjectInfo.Invoke(ManagedObject obj, InvokeType invokeType, String memberName, ScriptParam[] args) at System.Windows.Hosting.ManagedHost.InvokeScriptableMember(IntPtr pHandle, Int32 nMemberID, Int32 nInvokeType, Int32 nArgCount, ScriptParam[] pArgs, ScriptParam& pResult, ExceptionInfo& pExcepInfo)

before the function facebook_onlogin(session) is fired.

If you are allready logged in the following 2 exceptions occur.

uncaught exception: System.ArgumentException: Invalid args for this operation. Parameter name: args at System.Windows.Hosting.ScriptingInterface.ConvertFromScriptParams(ParameterInfo[] parameters, ScriptParam[] args) at System.Windows.Browser.ManagedObjectInfo.ScriptMethod.Invoke(ManagedObject obj, InvokeType invokeType, ScriptParam[] args) at System.Windows.Browser.ManagedObjectInfo.Invoke(ManagedObject obj, InvokeType invokeType, String memberName, ScriptParam[] args) at System.Windows.Hosting.ManagedHost.InvokeScriptableMember(IntPtr pHandle, Int32 nMemberID, Int32 nInvokeType, Int32 nArgCount, ScriptParam[] pArgs, ScriptParam& pResult, ExceptionInfo& pExcepInfo)
 
 Unhandled Error in Silverlight Application Could not invoke script function isUserConnected. Please ensure fblogin.js script is included OR this function exist in your script file at Facebook.Session.BrowserSession.<>c__DisplayClass1.<InvokeScriptCall>b__0()

Jun 14, 2010 at 9:16 PM
Edited Jun 14, 2010 at 9:17 PM

I've finally found the issue.
The problem is with the method JavaScript and the method signature of the LoggedIn( string, long ) 
In a nutshell JavaScript is passing both the Token and UserId parameters as strings so .NET isn't able to find a matching method signature. I changed the login method to
[ScriptableMember]        

public void LoggedIn(string accessToken, string userId)        

{

long lUserId;

if( long.TryParse(userId, out lUserId) )

this.UserId = lUserId;

else

throw new InvalidCastException("Login failed! The User ID passed by Facebook was invalid");

  this.UserId = long.Parse(userId);            

this.AccessToken = accessToken;
        this.OnLoggedIn(null);
}
accepting both parameters and do the type parsing afterwards and trowing an exception which will get caught by SilverLight when it fails.
Does anyone know who I should get in contact with to submit this so it can be placed into the main version?