Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Using with unity - "The application called an interface that was marshalled for a different thread" error #278

Open
thisloginalsotaken opened this issue Jun 17, 2019 · 2 comments

Comments

@thisloginalsotaken
Copy link

Hello.
I am trying to use this library with Unity application. I have created small library project and use it as "managed plugin" in Unity.
Unity version is 2018.3.6 (I tried 2019.1, with same result)
winsdkfb version is 0.15.0, installed with nuget.

Calling to session.LoginAsync always gives me WinRT originate error - 0x8001010E : 'The application called an interface that was marshalled for a different thread.'

I have tried wrapping the call in Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsyncwith no success. Rewriting the code to use without using async/await, with
session.LoginAsync(permissions).AsTask().ContinueWith((Task<FBResult> t) => {...}) also did no good.

Thank you.

@ehdgns3136
Copy link

Same here.
Have you resolved that problem ?

@BennyFranco
Copy link

Hi! I solved that issue calling the FB functions inside of
UnityEngine.WSA.Application.InvokeOnUIThread(async () => { }, false); the first time that I call an async function, then for the rest of async calls, you should call it inside of
UnityEngine.WSA.Application.InvokeOnAppThread(async () =>{ }, false);

Here is an example:

#if ENABLE_WINMD_SUPPORT
    UnityEngine.WSA.Application.InvokeOnAppThread(async () =>
    {
        List<string> permissionList = new List<string>
        {
            "email",
            "public_profile",
            "user_friends"
        };
        
        FBSession sess = FBSession.ActiveSession;
        sess.FBAppId = 0000; // AppID here
        sess.WinAppId = "" // WinAppId here

        FBPermissions permissions = new FBPermissions(permissionList);
        FBResult result = await sess.LoginAsync(permissions, SessionLoginBehavior.WebAuth);

        if (result.Succeeded)
        {
            // Login success
        }
        else
        {
            // Login failed
        }
    }, false);
#endif

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants