MFC application Crashes intermittently in Clr.dll with internal error in the .Net Runtime ( Windows 10)

Kumar Manish 1 Reputation point
2021-12-01T10:22:50.493+00:00

We have a C++ MFC application with COM interop for Managed C# code. Recently migrated to Windows 10 from windows 7.

Application crashes intermittently pointing to below information in crash dump

Exception code: C0000005
Exception Info: The thread tried to read from or write to a virtual address for which it does not have the appropriate access.

And in Event log Error "The process was terminated due to an internal error in the .Net Runtime at IP xxxxxxxxx with exit code 80131506"

Please find below information from extracted from crash dump through DebugDiag tool.

NET Call Stack

[[ComMethodFrame]]
DomainBoundILStubClass.IL_STUB_PInvoke()+68
[[InlinedCallFrame] (.wWinMainCRTStartup)] .wWinMainCRTStartup()
[[GCFrame]]

Full Call Stack

clr!COMToCLRWorker+a4
clr!GenericComCallStub+57
[[ComMethodFrame]]
myapp+3bcac1
myapp+11fe20
myapp+dacf9
mfc140u!CWnd::OnWndMsg+bdd
mfc140u!CWnd::WindowProc+3f
mfc140u!AfxCallWndProc+135
mfc140u!AfxWndProc+54
mfc140u!AfxWndProcBase+51
user32!UserCallWinProcCheckWow+266
user32!DispatchClientMessage+9c
user32!_fnDWORD+33
ntdll!KiUserCallbackDispatcherContinue
win32u!NtUserGetMessage+14
user32!GetMessageW+2d
mfc140u!AfxInternalPumpMessage+27
mfc140u!CWnd::RunModalLoop+108
mfc140u!CWnd::CreateRunDlgIndirect+3f
mfc140u!CDialog::DoModal+18b
myapp+36b5e9
myapp+3711f6
myapp+3728f6
mfc140u!AfxWinMain+84
myapp+4dfe1e
DomainBoundILStubClass.IL_STUB_PInvoke()+68
[[InlinedCallFrame] (<Module>.wWinMainCRTStartup)] <Module>.wWinMainCRTStartup()
clr!CallDescrWorkerInternal+83
clr!CallDescrWorkerWithHandler+4e
clr!MethodDescCallSite::CallTargetWorker+102
clr!RunMain+266
[[GCFrame]]
clr!Assembly::ExecuteMainMethod+b7
clr!SystemDomain::ExecuteMainMethod+643
clr!ExecuteEXE+3f
clr!_CorExeMainInternal+b2
clr!CorExeMain+14
mscoreei!CorExeMain+112
mscoree!CorExeMain_Exported+6c
kernel32!BaseThreadInitThunk+14
ntdll!RtlUserThreadStart+21

-------------------------------------------------------------------

Finalizer Thread

ntdll!NtWaitForSingleObject+14
KERNELBASE!WaitForSingleObjectEx+93
clr!CLREventWaitHelper2+3c
clr!CLREventWaitHelper+1f
clr!CLREventBase::WaitEx+7c
clr!FinalizerThread::WaitForFinalizerEvent+44
clr!FinalizerThread::FinalizerThreadWorker+54
clr!ManagedThreadBase_DispatchInner+39
clr!ManagedThreadBase_DispatchMiddle+6c
clr!ManagedThreadBase_DispatchOuter+75
[[DebuggerU2MCatchHandlerFrame]]
clr!FinalizerThread::FinalizerThreadStart+126
clr!Thread::intermediateThreadProc+86
kernel32!BaseThreadInitThunk+14
ntdll!RtlUserThreadStart+21

154121-microsoftteams-image.png153980-microsoftteams-image-1.png

Requesting your support for fixing the issue.

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
10,718 questions
.NET CLI
.NET CLI
A cross-platform toolchain for developing, building, running, and publishing .NET applications.
324 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,547 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,127 questions
{count} votes

2 answers

Sort by: Most helpful
  1. EckiS 821 Reputation points
    2021-12-01T18:29:04.447+00:00

    probably your code corrupted internal structures, see a similar issue:
    net-runtime-error-80131506-passing-lambda-to-native-function

    Can you reproduce when compiled for Debug and started from Visual Studio with Mixed Mode Debugging?
    how-to-debug-in-mixed-mode
    Make sure to enable all MDA's


  2. Limitless Technology 39,396 Reputation points
    2021-12-08T08:43:07.697+00:00

    Hi there,

    The exception code 0xc0000005 indicates a memory access violation.
    According to the information you've provided, it looks like the OCX control you're using is performing an illegal access to the memory, therefore the system raised the exception and halted the program's execution.

    Your computer may have a virus and the 0xC0000005 error informs that the system prevented execution of a malicious application. Try running an full system scan.

    You can also try updating the BIOS and video drivers of the PC and try running the MFC applications.


    --If the reply is helpful, please Upvote and Accept it as an answer--