IL Linker tries to remove unreachable basic blocks from exception filter blocks, but may strip the endfilter instruction in the process, making the IL invalid.
Ran into this in the CoreCLR Pri0 test suite because Native AOT also imported this bug. The CoreCLR test is in IL but it can be reached with C# - this is the simplest way to reach it (pardon the nonsensical code, didn't want to think about this much):
try
{
throw new Exception();
}
catch when (IntPtr.Size == 8 ? throw new Exception() : true)
{
Console.WriteLine("Hey");
}