Thanks for reaching out.
The error 0xC0000005 Access violation reading location 0xFFFFFFFFFFFFFFFF combined with FatalExecutionEngineError usually indicates memory corruption or invalid pointer access in unmanaged code. This often occurs when:
- Incorrect COM Interop or P/Invoke marshalling (mismatched data types or structures between C# and C++)
- Unsafe code or stack corruption in the native DLL
- Race conditions when multiple threads access shared memory without proper synchronization Why it happens intermittently
Memory corruption doesn’t always trigger immediately—it depends on timing, heap layout, and thread scheduling. That’s why the same procedure can succeed multiple times before failing.
How to troubleshoot and fix
- Enable Native + Managed Debugging In Visual Studio: Project Properties → Debug → Enable native code debugging This lets you step into the C++ DLL and inspect the crash point.
- Verify P/Invoke Signatures Ensure all parameters match exactly between C# and C++ (types, calling conventions). Use
[StructLayout(LayoutKind.Sequential)]for structs. - Check Memory Handling in C++ Avoid returning pointers to freed memory. Use smart pointers or RAII patterns.
- Run with PageHeap or Application Verifier These tools detect heap corruption early.
- Ensure Thread Safety If WCF calls are multi-threaded, confirm the native DLL is thread-safe.
Helpful References
- https://free.blessedness.top/en-us/dotnet/framework/debugging/fatalexecutionengineerror
- https://free.blessedness.top/en-us/dotnet/standard/native-interop/pinvoke
- https://free.blessedness.top/en-us/dotnet/framework/interop/
Could you share:
- The P/Invoke signature in C# and the corresponding C++ function declaration?
- Whether the DLL uses callbacks or unmanaged memory allocation?
This will help pinpoint the exact marshalling issue.
Let me know if the issue persists after following these steps. I’ll be happy to assist further if needed. If the issue has been resolved, please click "Accept Answer".