locked
Strange exception in the Frame::Navigate method

    Question

  • I am having an exception when using Frame::Navigate method. The exception itself isn't caught by Visual Studio debugger.
    The exception isn't accompanied by any text description.

    As a result of that exception the program is stopped at the following place (auto generated code in App.g.hpp)
    void ::SpecialistMetro::App::InitializeComponent()
    {
    #if defined _DEBUG && !defined DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
        UnhandledException += ref new Windows::UI::Xaml::UnhandledExceptionEventHandler(
            [](::Platform::Object^ sender, ::Windows::UI::Xaml::UnhandledExceptionEventArgs^ e)
            {
                (void)sender; // Unused parameter
                if (IsDebuggerPresent())
                {
                    ::Platform::String^ errorMessage = e->Message;
                    __debugbreak();
                }
            });
    #endif
    }

    The e->Message here is NULL, so I have no info on the situation.
    Here is the stack.
    > SpecialistMetro.exe!<lambda_dc76b85b41b41ce88cb5362a14ae82b6>::operator()(Platform::Object ^ sender=0x003eef44, Windows::UI::Xaml::UnhandledExceptionEventArgs ^ e=0x0ed65220) Line 58 C++
      SpecialistMetro.exe!Platform::Details::__abi_FunctorCapture2<<lambda_dc76b85b41b41ce88cb5362a14ae82b6>,void,Platform::Object ^,Windows::UI::Xaml::UnhandledExceptionEventArgs ^>::Invoke(Platform::Object ^ __arg0=0x003eef44, Windows::UI::Xaml::UnhandledExceptionEventArgs ^ __arg1=0x0ed65220) Line 864 C++
      SpecialistMetro.exe!Windows::UI::Xaml::UnhandledExceptionEventHandler::Invoke(Platform::Object ^ __param0=0x003eef44, Windows::UI::Xaml::UnhandledExceptionEventArgs ^ __param1=0x0ed65220) C++
      SpecialistMetro.exe!Windows::UI::Xaml::UnhandledExceptionEventHandler::[Windows::UI::Xaml::UnhandledExceptionEventHandler::__abi_IDelegate]::__abi_Windows_UI_Xaml_UnhandledExceptionEventHandler___abi_IDelegate____abi_Invoke(Platform::Object ^ __param0=0x003eef44, Windows::UI::Xaml::UnhandledExceptionEventArgs ^ __param1=0x0ed65220) C++
      Windows.UI.Xaml.dll!DirectUI::CFTMEventSource<Windows::UI::Xaml::IUnhandledExceptionEventHandler,Windows::UI::Xaml::IApplication,Windows::UI::Xaml::IUnhandledExceptionEventArgs>::Raise(Windows::UI::Xaml::IApplication * pSource=0x003eef44, Windows::UI::Xaml::IUnhandledExceptionEventArgs * pArgs=0x0ed65220) Line 327 C++
      Windows.UI.Xaml.dll!DirectUI::Application::RaiseUnhandledExceptionEventHelper(long hrEncountered=-2147467259, unsigned short * pszErrorMessage=0x00000000, unsigned int * pfIsHandled=0x043ff230) Line 920 C++
      Windows.UI.Xaml.dll!DirectUI::ErrorHelper::CallAUHandler(unsigned int errorCode=2147500037, unsigned int * pfIsHandled=0x043ff230, wchar_t * * pbstrErrorMessage=0x043ff228) Line 39 C++
      Windows.UI.Xaml.dll!DirectUI::ErrorHelper::ProcessUnhandledErrorForUserCode(long error=-2147467259) Line 82 C++
      Windows.UI.Xaml.dll!DirectUI::DXamlCore::FireEvent(CDependencyObject * unmanagedObj, CDependencyObject * unmanagedObjArgs, int argsTypeIndex, unsigned short * eventName, unsigned int flags) C++
      Windows.UI.Xaml.dll!AgCoreCallbacks::FireEvent(CDependencyObject * unmanagedObj=0x0975e6a8, CDependencyObject * unmanagedObjArgs=0x148d7d48, int argsTypeIndex=31, int actualArgsTypeIndex=31, unsigned short * eventName=0x149417e8, unsigned int flags=360) Line 228 C++
      Windows.UI.Xaml.dll!CCoreServices::CLR_FireEvent(IDependencyObject * pSender=0x0975e6a8, IDependencyObject * pe=0x148d7d48, unsigned short * pName=0x149417e8, unsigned int flags=360) Line 5013 C++
      Windows.UI.Xaml.dll!CommonBrowserHost::CLR_FireEvent(IDependencyObject * pSender=0x0975e6a8, IDependencyObject * pe=0x148d7d48, CXString * pName=0x149417d8, unsigned int flags=360) Line 1089 C++
      Windows.UI.Xaml.dll!CControlBase::ScriptCallback(void * pControl=0x007ba3c4, IDependencyObject * pSender, IDependencyObject * pe, CXString * pstrName=0x149417d8, int flags, IScriptObject * pScriptObject, long (IDependencyObject *, IDependencyObject *) * pInternalHandler) Line 539 C++
      Windows.UI.Xaml.dll!CXcpDispatcher::OnScriptCallback(CEventInfo * pEventInfo=0x007ba3c4) Line 1012 C++
      Windows.UI.Xaml.dll!CXcpDispatcher::OnWindowMessage(HWND__ * msg=0, unsigned int wParam=0, unsigned int lParam=345253832, long) Line 854 C++
      Windows.UI.Xaml.dll!CXcpDispatcher::WindowProc(HWND__ * hwnd, unsigned int msg, unsigned int wParam, long lParam) C++
      user32.dll!_InternalCallWinProc@20() Unknown
      user32.dll!_UserCallWinProcCheckWow@36() Unknown
      user32.dll!_DispatchClientMessage@24() Unknown
      user32.dll!___fnDWORD@4() Unknown
      ntdll.dll!_KiUserCallbackDispatcher@12() Unknown
      Windows.UI.Xaml.dll!CXString::Create(unsigned int cch=43692032, unsigned int bPublic) Line 76 C++
      user32.dll!_SendMessageW@16() Unknown
      Windows.UI.Xaml.dll!CXcpBrowserHost::SyncScriptCallbackRequest(void * pVoidBH=0x0030c7f0, IDependencyObject * pSender=0x0975e6a8, IDependencyObject * pe=0x148d7d48, CXString * pstrFName=0x043ff658, int flags=360, IScriptObject * pScriptObject=0x00000000, long (IDependencyObject *, IDependencyObject *) * pHandler=0x00000000) Line 2161 C++
      Windows.UI.Xaml.dll!CEventManager::RaiseHelper(xvector<REQUEST *> * pRegisteredRequests, CDependencyProperty * pEvent, CDependencyObject * pSender, CEventArgs * pArgs, int bRefire, long (void *, IDependencyObject *, IDependencyObject *, CXString *, int, IScriptObject *, long (IDependencyObject *, IDependencyObject *) *) * pfnScriptCallback, unsigned int & bFired, CDependencyObject * pSenderOverride) Line 1111 C++
      Windows.UI.Xaml.dll!CEventManager::RaiseLoadedEvent() Line 798 C++
      Windows.UI.Xaml.dll!CCoreServices::NWDrawTree(HWWalk * pHWWalk, ICoreRenderTarget * pIRenderTarget, VisualTree * pVisualTree, unsigned int uBackgroundColor, unsigned int forceRedraw, unsigned int needsToReleaseHardwareResources, XRECT_WH * prcDirtyRect) Line 10851 C++
      Windows.UI.Xaml.dll!CCoreServices::NWDrawMainTree(ICoreRenderTarget * pIRenderTarget=0x0035e63c, unsigned int fForceRedraw=0, unsigned int needsToReleaseHardwareResources=0, XRECT_WH * prcDirtyRect=0x043ff82c) Line 10697 C++
      Windows.UI.Xaml.dll!CWindowRenderTarget::Draw(ICoreServices * pCore=0x003182d0, unsigned int fForceRedraw=0, XRECT_WH * prcDirtyRect=0x043ff82c) Line 128 C++
      Windows.UI.Xaml.dll!CXcpBrowserHost::OnTick() Line 1160 C++
      Windows.UI.Xaml.dll!CXcpDispatcher::Tick() Line 1120 C++
      Windows.UI.Xaml.dll!CXcpDispatcher::OnReentrancyProtectedWindowMessage(HWND__ * msg=1026, unsigned int wParam=0, unsigned int lParam=0, long) Line 653 C++
      Windows.UI.Xaml.dll!CXcpDispatcher::WindowProc(HWND__ * hwnd=0x00280382, unsigned int msg=1026, unsigned int wParam=0, long lParam=0) Line 401 C++
      user32.dll!_InternalCallWinProc@20() Unknown
      user32.dll!_UserCallWinProcCheckWow@36() Unknown
      user32.dll!_DispatchMessageWorker@8() Unknown
      user32.dll!_DispatchMessageW@4() Unknown
      Windows.UI.dll!Windows::UI::Core::CDispatcher::ProcessMessage(int bDrainQueue=1, int * pbAnyMessages=0x043ffa18) Line 116 C++
      Windows.UI.dll!Windows::UI::Core::CDispatcher::ProcessEvents(Windows::UI::Core::CoreProcessEventsOption options=CoreProcessEventsOption_ProcessUntilQuit) Line 184 C++
      Windows.UI.Xaml.dll!CJupiterWindow::RunCoreWindowMessageLoop() Line 416 C++
      Windows.UI.Xaml.dll!CJupiterControl::RunMessageLoop() Line 714 C++
      Windows.UI.Xaml.dll!DirectUI::DXamlCore::RunMessageLoop() Line 2538 C++
      Windows.UI.Xaml.dll!DirectUI::FrameworkView::Run() Line 91 C++
      twinapi.dll!`Windows::ApplicationModel::Core::CoreApplicationViewAgileContainer::RuntimeClassInitialize'::`55'::<lambda_A2234BA2CCD64E2C>::operator()(void * pv=0x0096a508) Line 560 C++
      twinapi.dll!`Windows::ApplicationModel::Core::CoreApplicationViewAgileContainer::RuntimeClassInitialize'::`55'::<lambda_A2234BA2CCD64E2C>::<helper_func>(void * pv=0x0096a508) Line 613 C++
      SHCore.dll!_SHWaitForThreadWithWakeMask@12() Unknown
      kernel32.dll!@BaseThreadInitThunk@12() Unknown
      ntdll.dll!___RtlUserThreadStart@8() Unknown
      ntdll.dll!__RtlUserThreadStart@8() Unknown

    The exception occurs quite deterministically:
    I have two pages and have a listbox that, on selection, navigates to the selected page.
    Here is the code that is executed when the selection changed:

    void App::NavigateToNextConn (ClientConnection^ conn)
    {
     getRootFrame()->Dispatcher->RunAsync(CoreDispatcherPriority::Normal,ref new DispatchedHandler([=](){
      if (conn == nullptr)
       getRootFrame()->Navigate (Windows::UI::Xaml::Interop::TypeName(HomePageNew::typeid));
      else
       getRootFrame()->Navigate (Windows::UI::Xaml::Interop::TypeName(InSessionPage::typeid), conn);
     }));
    }

    In my case conn isn't nullptr. I have two pages of the same type - InSessionPage, page1 and page2. When the page1 is displayed,
    I do the following:
    1. navigate to the page2 via the above list box;
    2. navigate back to the page1.

    The exception occurs at the step 2. Step 1 completes normally.

    Some investigations with Visual Studio debugger allow me to state that the failure occurs in the following place in the DirectUI::BindingExpression::ConnectToEffectiveSource:

    pListener is 00000000 in my case.
    705E91EC 8B 45 F4             mov         eax,dword ptr [pListener] 
    705E91EF 89 46 58             mov         dword ptr [esi+58h],eax 
    705E91F2 FF 76 64             push        dword ptr [esi+64h] 
    705E91F5 8B 4E 58             mov         ecx,dword ptr [esi+58h] 
    705E91F8 E8 17 00 00 00       call        DirectUI::PropertyPathListener::SetSource (705E9214h) 
    705E91FD 8B F0                mov         esi,eax 
    705E91FF 85 F6                test        esi,esi 
    705E9201 0F 88 0C 70 0B 00    js          Cleanup+0B7009h (706A0213h) 

    I would like someone to explain what is the root of the trouble so that I could fix it.

    Thank you.

    Sunday, June 16, 2013 9:21 PM