You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 13, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Nov 13, 2026. It is now read-only.
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).
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).
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.
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), ....
@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!
Activity
wjk commentedon Jul 10, 2016
Clarification: The assertion detailed above occurs anywhere an exception is thrown (by the runtime, by a corefx library, or by a
throwstatement in application code).wjk commentedon Jul 10, 2016
Furthermore, as far as I can tell theI 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 thetryblock is not emitted into the generated assembler by ILC. The contents of thecatchblock 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.CoffNativeCodeManager.jkotas commentedon Jul 11, 2016
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 toRhpRegisterCoffModule(PalGetModuleHandleFromPointer((void*)&AppMain), ....wjk commentedon Jul 11, 2016
@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!
wjk commentedon Jul 12, 2016
@jkotas I have now confirmed that your change did the trick. Throwing and catching exceptions now works as expected.