Code Monkey home page Code Monkey logo

Comments (9)

ehdgns3136 avatar ehdgns3136 commented on May 24, 2024

After some debugging, i find out that this is because of below exception.

Exception : The application called an interface that was marshalled for a different thread.

And this exception is thrown every time trying to initialize FacebookDialog like below code in FacebookSession.cpp.

auto callback = ref new DispatchedHandler(
        [=]()
    {
        try
        {
            _dialog = ref new FacebookDialog();
            create_task(_dialog->ShowLoginDialog(Parameters)).then([=](FBResult ^result)
            {
                dialogResponse.set(result);
            });
        }
        catch (Exception^ ex)
        {
            FBError^ err = FBError::FromJson(ref new String(ErrorObjectJson));
            dialogResponse.set(ref new FBResult(err));
        }
    });

Well, i guess this happens probably while initializing FacebookDialog.xaml, but i don't know exact reason because i can't specify which line that exception thrown from.
Debugger just escape from the code at line that i specify below in the constructor of FacebookDialog before getting into InitializeComponent.

FacebookDialog::FacebookDialog()
{ <- here !
    InitializeComponent();
    InitDialog();
}

Google says that exception happens when i try to access thread from another thread and it can be resolved with this which is here link.

Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
() =>
    {
        // Your UI update code goes here!
    }
);

But isn't it true that dialog is already executed like below in FacebookSession.cpp

Windows::UI::Core::CoreWindow^ wnd = CoreApplication::MainView->CoreWindow;

wnd->Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, callback);

Is there anyone who suffer from similar problem with me?
I develop on a Windows 10 and try to show dialog on a app which is generated by Unity.

from winsdkfb.

johanlindfors avatar johanlindfors commented on May 24, 2024

It would be awesome if you could share a minimal reproducable sample which could help me or someone else debug the issue. But reading your latest comments, if you use the FacebookSession API to login, the FacebookSession has a dispatcher functionality as described, but if you instead use the FacebookDialog directly as in your code sample, you probably have to wrap the UI calls manually with the dispatcher. Does that make sense?

from winsdkfb.

ehdgns3136 avatar ehdgns3136 commented on May 24, 2024

Thanks for the comment.

There is the core process which is the way that i try to login at below.
In the line of sess->LoginAsync, you can pass the parameter which decide the way to login internally in winsdkfb like WebView, WebAuth, WebAccountProvider or DefaultOrdering.
The WebAuth flag works, but the others don't.
And i already wrap them with the dispatcher.
Is there anything wrong among that i have done on my code?

Well, i check which thread does those process run and figured out those process are running on SHCore.dll thread which is UI Thread in windows.
But the weird thing is, there exist several SHCore.dll thread running like 2 or 3 while playing the app.
I'm very new to UWP and C++, so i'm not sure exactly that this is usual case or not.

Right now, i suspect several things and try to look into.
For example, because i'm running the app on Unity UWP app, there could be something wrong in the way that i try to run it.
Or, from the fact that there exist several UI Thread, when Dialog try to appear, it try to make another UI Thread and appear on it and try to interact with the UI Thread that already exist.

void RunOnWindowsUIThread(const std::function<void()>& handler) {
	Windows::ApplicationModel::Core::CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(CoreDispatcherPriority::Normal, ref new DispatchedHandler(handler));
}

void _stdcall loginFacebook(const wchar_t*) {
	RunOnWindowsUIThread([] {
                 loginFacebook();
	});
}

void loginFacebook() {
	FBSession^ sess = FBSession::ActiveSession;
	sess->FBAppId = FB_APP_ID;
	sess->WinAppId = WIN_APP_ID;

	// Add permissions required by the app
	Vector<String^>^ permissionList = ref new Vector<String^>();
	permissionList->Append(L"public_profile");
	permissionList->Append(L"user_friends");
	FBPermissions^ permissions = ref new FBPermissions(permissionList->GetView());

	// Login to Facebook
        sess->LoginAsync(permissions);
}

from winsdkfb.

johanlindfors avatar johanlindfors commented on May 24, 2024

You'll have to excuse me here, since I haven't leveraged C++/CX from any Unity applications/games earlier and hence are wondering if there might be something causing issues in that?

from winsdkfb.

ehdgns3136 avatar ehdgns3136 commented on May 24, 2024

Yeah, there might be or might be not.
I just suspect all possibility.

Thank you for your comment and i'll update this issue when i can resolve this problem.

from winsdkfb.

johanlindfors avatar johanlindfors commented on May 24, 2024

Sorry for not being able to help directly here, but have you tried leveraging the nuget packages for winsdkfb instead of the branch directly? My thinking is, then you could at least remove one layer of abstraction and possibly the burden of C++/CX.

I am really curious about this issue though and if I have time I will try to setup a Unity project leveraging winskdb myself, it will be a valuable lesson for me as well.

from winsdkfb.

ehdgns3136 avatar ehdgns3136 commented on May 24, 2024

By the way, below is stack trace when i try to use the method LoginAsnyc and those korean sentences mean just exception "The application called an interface that was marshalled for a different thread"

Exception thrown at 0x00007FF96F179129 in MyApp.exe: Microsoft C++ exception: Platform::WrongThreadException ^ at memory location 0x0000004A504FEEB0. HRESULT:0x8001010E 응용 프로그램이 다른 스레드를 위해 배열된 인터페이스를 호출했습니다.
WinRT information: 응용 프로그램이 다른 스레드를 위해 배열된 인터페이스를 호출했습니다.
Stack trace:
combase.dll!00007ff972a703f1()
vccorlib140_app.dll!00007ff9412487c5()
vccorlib140_app.dll!00007ff941249d57()
winsdkfb.dll!__abi_WinRTraiseException(long __hrArg) Line 1125
[Inline Frame] winsdkfb.dll!__abi_ThrowIfFailed(long) Line 100
winsdkfb.dll!Windows::UI::Xaml::Controls::IUserControlFactory::CreateInstance(Platform::Object ^ __param0, Platform::Object ^ * __param1)
winsdkfb.dll!Windows::UI::Xaml::Controls::UserControl::UserControl()
winsdkfb.dll!winsdkfb::FacebookDialog::FacebookDialog() Line 93
winsdkfb.dll!winsdkfb::FBSession::ShowLoginDialog::__l2::() Line 577
winsdkfb.dll!Windows::UI::Core::DispatchedHandler::[Windows::UI::Core::DispatchedHandler::__abi_IDelegate]::__abi_Windows_UI_Core_DispatchedHandler___abi_IDelegate____abi_Invoke()
Windows.UI.dll!Windows::UI::Core::CDispatcher::ProcessInvokeItem(bool * pbInvokeItemProcessed) Line 1266
Windows.UI.dll!Windows::UI::Core::CDispatcher::ProcessMessage(bool bDrainQueue, bool * pbWindowMessagesProcessed, bool * pbInvokeItemProcessed) Line 270
Windows.UI.dll!Windows::UI::Core::CDispatcher::WaitAndProcessMessagesInternal(bool bRunAlwaysOnce, void * hEventWait) Line 1953
Windows.UI.dll!Windows::UI::Core::CDispatcher::ProcessEvents(Windows::UI::Core::CoreProcessEventsOption options) Line 599
UnityPlayer.dll!00007ff8f9ca6e18()
UnityPlayer.dll!00007ff8f8da5098()
MyApp.exe!UnityPlayer::__IAppCallbacksPublicNonVirtuals::Run()
MyApp.exe!MyApp::App::[Windows::ApplicationModel::Core::IFrameworkView]::Run() Line 49
MyApp.exe!MyApp::App::[Windows::ApplicationModel::Core::IFrameworkView]::__abi_Windows_ApplicationModel_Core_IFrameworkView____abi_Run()
twinapi.appcore.dll!00007ff96d5c4c2a()
twinapi.appcore.dll!00007ff96d597a66()
SHCore.dll!00007ff972d4c315()
kernel32.dll!00007ff970157974()
ntdll.dll!00007ff972eda271()

from winsdkfb.

ehdgns3136 avatar ehdgns3136 commented on May 24, 2024

Oh yeah, the first try that i install winsdkfb is through nuget package manager in visual studio.
But because i want to get symbol file and debug internal part of sdk, i download sdk and build it, add reference to my project directly.

With further debugging and checking from stack trace, i think i found out the actual part which makes problem.
If you see the stack traces, almost just before exception is thrown, you can see FacebookDialog is try to be initialized with constructor.

winsdkfb.dll!winsdkfb::FacebookDialog::FacebookDialog() Line 93.

And if you see this line in FacebookDialog.xaml.cpp, it tries to call InitializeComponent() which exist in FacebookDialog.g.hpp file.

FacebookDialog::FacebookDialog()
{
    InitializeComponent(); <- Line 93 !
    InitDialog();
}

And if you see this method in FacebookDialog.g.hpp, in the end of method, it tries to LoadComponent from FacebookDialog.xaml.

void ::winsdkfb::FacebookDialog::InitializeComponent()
{
    if (_contentLoaded)
    {
        return;
    }
    _contentLoaded = true;
    ::Windows::Foundation::Uri^ resourceLocator = ref new ::Windows::Foundation::Uri(L"ms-appx:///winsdkfb/FacebookDialog.xaml");
    ::Windows::UI::Xaml::Application::LoadComponent(this, resourceLocator, ::Windows::UI::Xaml::Controls::Primitives::ComponentResourceLocation::Nested);
}

Google says that LoadComponent is to make the most upper class of corresponding xaml file to be initialized and that class is UserControl.
And if you see further stack trace after that, you can see UserControl is being initialized and try to call CreateInstance method.

winsdkfb.dll!Windows::UI::Xaml::Controls::IUserControlFactory::CreateInstance(Platform::Object ^ __param0, Platform::Object ^ * __param1)
winsdkfb.dll!Windows::UI::Xaml::Controls::UserControl::UserControl()

And immediately after that, exception is thrown.
So i suspect that this is actual line that exception is thrown where UserControl is initialized.
But i have no idea what happen when UserControl is initialized.

In relation to this, another thing i suspect is that there exist more than one SHCore.dll thread in run time.
As i know, SHCore.dll thread is UI Thread and basically UI Thread have to be remained only one.
The reason why it throws exception even though i wrap the call which makes UI(request LoginDialog) might be because there exist more than one UI Thread and try to interact with each other.
Well, i'm not an expert on UWP and C++/CX but as far as i think, this is the conclusion that i can get.

Please share your opinion if you have any idea about those fact.
Thanks!

from winsdkfb.

truthfinder avatar truthfinder commented on May 24, 2024

Hello,
We use winsdkfb and have faced the same issue. Exception::HRESULT is RPC_E_WRONG_THREAD. As I understand from comments SHCore.dll is UIThread, so I don't have any idea what thread should it be to be called correctly.
It's a pity that current state of the issue look suspended, because this functionality is critical for us. Is it possible to do something to fix this issue? Or maybe provide some additional information to fix it?
Best regards,
Vyacheslav

from winsdkfb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.