Skip to content
This repository was archived by the owner on Nov 13, 2026. It is now read-only.
This repository was archived by the owner on Nov 13, 2026. It is now read-only.

Exception-handling assertion failure #1498

Closed

Description

@wjk

I am working on a CoreRT-based project that is throwing an exception in a P/Invoke function. That is not the problem I am reporting here, however. The problem I am reporting here is that if I throw an exception, I then get an assertion failure and __debugbreak() with the following call stack (copied directly from the Visual Studio C++ debugger):

    ChocoTester.Application.dll!PalDebugBreak() Line 1289   C++
    ChocoTester.Application.dll!Assert(const char * expr, const char * file, unsigned int line_num, const char * message) Line 51   C++
    ChocoTester.Application.dll!StackFrameIterator::CalculateCurrentMethodState() Line 1466 C++
    ChocoTester.Application.dll!RhpSfiInit(StackFrameIterator * pThis, PAL_LIMITED_CONTEXT * pStackwalkCtx) Line 1638   C++
    ChocoTester.Application.dll!System_Private_CoreLib_System_Runtime_EH__DispatchEx()  Unknown
    ChocoTester.Application.dll!RhThrowEx() Unknown
    ChocoTester.Application.dll!RhpThrowEx() Line 198   Unknown
    ChocoTester.Application.dll!ChocoTester_Main_ChocoTester_Main_Program__Main()   Unknown
    ChocoTester.Application.dll!ChocoTester_Main__Module___StartupCodeMain()    Unknown
    ChocoTester.Application.dll!AppMain(int argc, wchar_t * * argv) Line 316    C++
    choco-tester.exe!wWinMain(HINSTANCE__ * hInstance, HINSTANCE__ * __formal, wchar_t * cmdLine, int nCmdShow) Line 21 C++
    choco-tester.exe!invoke_main() Line 118 C++
    choco-tester.exe!__scrt_common_main_seh() Line 253  C++
    choco-tester.exe!__scrt_common_main() Line 296  C++
    choco-tester.exe!wWinMainCRTStartup() Line 17   C++
    kernel32.dll!BaseThreadInitThunk()  Unknown
    ntdll.dll!RtlUserThreadStart()  Unknown

Apparently, the CoffNativeCodeManager::FindMethodInfo method is not finding the appropriate method. Inspection in the debugger reveals that the relativePC passed to LookupUnwindCodeForMethod() is unusually large (as in, five or more place-values larger than the values in the pRuntimeFunctionTable). I do not know enough about CoreRT to diagnose the issue further.

My first wild guess is a 32-bit-versus-64-bit value-truncation issue, but my application under CoreRT runs just fine until it throws an exception. However, the CoreRT exception unit tests pass perfectly well, without this problem, despite them also running in 64-bit (at least, as far as I can tell).

Activity

  1. wjk commented on Jul 10, 2016

    @wjk
    ContributorAuthor

    Clarification: The assertion detailed above occurs anywhere an exception is thrown (by the runtime, by a corefx library, or by a throw statement in application code).

  2. wjk commented on Jul 10, 2016

    @wjk
    ContributorAuthor

    Furthermore, as far as I can tell the try block is not emitted into the generated assembler by ILC. The contents of the catch block are present and as expected, but I can see no code whatsoever that informs the runtime about its presence. The symptoms described above may or may not be caused by the exception actually being unhandled at runtime. I was wrong. Further exploration in the debugger reveals that unwind info is stored in a data blob and is pulled out of the object by the CoffNativeCodeManager.

  3. jkotas commented on Jul 11, 2016

    @jkotas
    Member

    I see that you are building the managed code as .dll, not as .exe. Have you done the matching change in for RhpRegisterCoffModule? RhpRegisterCoffModule(GetModuleHandleW(NULL) needs to be changed to register the .dll module, e.g. change it to RhpRegisterCoffModule(PalGetModuleHandleFromPointer((void*)&AppMain), ....

  4. wjk commented on Jul 11, 2016

    @wjk
    ContributorAuthor

    @jkotas As a matter of fact, no I did not. I can't confirm that this change fixes the issue at this very moment -- I am currently in the middle of debugging another issue -- but once I fix that, I will let you know. Thanks!

  5. wjk commented on Jul 12, 2016

    @wjk
    ContributorAuthor

    @jkotas I have now confirmed that your change did the trick. Throwing and catching exceptions now works as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions