A lot of this code has since been rewritten to fix problems like this. I’m followed your steps very particularly on the latest internal build, and I can’t seem to get it to repro.
I understand you’re using WMF 5 on Windows 7, but if you’ve got a test machine lying around, I highly encourage you to see if the Windows Insider build fixes your problem.
Either way, this should be fixed in a future version of Windows 10 (and potentially WMF as well).
JoeyMatt White commented
Sorry, took a couple days to get a Win10 box on an insider build. I've confirmed that the issue (both my reduced repro and the problem with our actual modules) are *not* reproducible on Win10 14295.
While that's great to see that it's fixed in a forthcoming build of Win10, it's less clear what that means for older OSes. I understand you may not be able to commit to anything, but any guidance you could provide about whether this will fix will ship (and if so a very rough idea of when) for Win7/2008R2 and 2012R2 would be greatly appreciated. If the answer is that it may not ship at all, or won't ship for 6+ months or something like that, then we'll still have to go patch our modules to somehow avoid this bug.