Extended Permissions in Silverlight!

Mar 3, 2010 at 10:22 AM

Hi i`m newbie to Facebook Development and currently examining the examples in codeplex..What i have in mind is to access the photos of the users while they are offline, ok i added the this code to require extended permission from the user to the SilverlightGettingStarted example..

private void CreateSession()
        {
            // Create session object (would protect app key, app secret in live application)
            Enums.ExtendedPermissions[] extper = { Enums.ExtendedPermissions.offline_access };
            Session = new BrowserSession("MyApiNumber", extper);

            // Wire up authentication event handlers
            Session.LoginCompleted += browserSession_LoginCompleted;
            Session.LogoutCompleted += browserSession_LogoutCompleted;
        }

private void browserSession_LoginCompleted(object sender, AsyncCompletedEventArgs e)
        {
            // Create instance of Toolkit API using our authenticated session
            API = new Api(Session);

            // Load user information asynchronously
            API.Users.GetInfoAsync(Session.UserId, GetUserInfoCompleted, null);
            //MessageBox.Show(Session.SessionKey);
            
            // Issue login event to subscribers
            OnLoginCompleted(e);
        }

 

I get the sessionkey which comes with the user`s id to use it for offline access, But when the user who had granted the permission logs in second time, an exception is thrown

Microsoft JScript runtime error: Unhandled Error in Silverlight Application Invalid cross-thread access.   at MS.Internal.XcpImports.CheckThread()
   at MS.Internal.XcpImports.SetValue(INativeCoreTypeWrapper obj, DependencyProperty property, Boolean b)
   at System.Windows.DependencyObject.SetValue(DependencyProperty property, Boolean b)
   at System.Windows.Controls.Control.set_IsEnabled(Boolean value)
   at GettingStarted.MainPage.SetAuthenticationStatus()
   at GettingStarted.MainPage.DataAccess_LoginCompleted(Object sender, EventArgs e)
   at GettingStarted.FacebookDataAccess.OnLoginCompleted(EventArgs e)
   at GettingStarted.FacebookDataAccess.browserSession_LoginCompleted(Object sender, AsyncCompletedEventArgs e)
   at Facebook.Session.FacebookSession.OnLoggedIn(Exception e)
   at Facebook.Session.BrowserSession.OnPermissionCheckCompleted(String accepted, Exception e)
   at Facebook.Session.BrowserSession.PermissionCheckCallBack(permissions_response permission, Object state, FacebookException ex)
   at Facebook.Rest.RestBase.OnFacebookCallCompleted[TObject,TResult](IAsyncResult result, String propName)
   at Facebook.Rest.RestBase.OnFacebookCallCompleted[T](IAsyncResult result)
   at Facebook.Utility.AsyncResult.SetComplete(String result, FacebookException e)
   at Facebook.Rest.RestBase.OnRequestCompleted(Object sender, RequestCompletedEventArgs e)
   at Facebook.Utility.WebClientHelper.BeginResponse(IAsyncResult ar)
   at System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClassd.<InvokeGetResponseCallback>b__b(Object state2)
   at System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack)
   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state)
What action should i take to avoid this exception when the user logs second time?