Skip to content

ExecutionEngineException after GC.Collect when using global hook #43196

@Germs2004

Description

@Germs2004

Issue Title

Reproducible crash caused by garbage collection after installing a global keyboard hook.

General

The crash is reproducible every time. I created a whole new project to demo the problem. Here's how it works:

  1. Run the .Net Core 3.1 desktop app.
  2. It adds a global keyboard hook using Windows API
  3. The hook works fine and you can press lots of keys, no problem.
  4. Garbage collection runs
  5. Now, the first key you press, it will crash the program with ExecutionEngineException. It seems that garbage collection breaks something with the keyboard hook.

I can't find anybody else with this problem and can't find any solution. Several people have reported a different crash with ExecutionEngineException where disabling ConcurrentGarbageCollection solves their issue, but that solution does not work with my problem. Am I doing something wrong, or is there some workaround I can use until this gets fixed upstream?

Windows 10 2004, all updates applied
.Net Core 3.1
Visual Studio 2019 16.7.5

Very simple Visual Studio solution attached as a Zip file to demonstrate the issue.

HookTest.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-Interop-coreclrquestionAnswer questions and provide assistance, not an issue with source code or documentation.untriagedNew issue has not been triaged by the area owner

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions