|Eureka! I have found it!
After hours of trying various debuggers and debugging strategies, countless cups of good strong tea and not a few words of frustration and annoyance I have located and fixed the problem.
Buried deep in my own initialisation code, in a place I haven't visited for years and had forgotten all about is a call to a function called
SetThreadName which uses exception 0x406d1388 . This was being compiled as managed code so the framework was seeing the exception even before the catch block in the same function. The solution was simply to mark that function as
unmanaged (and then drink more tea ).