Article

Why didn’t we use Co­Register­Initialize­Spy to clean up the unmarshalable delegate?

The Old New Thing ·The Old New Thing ·Published 2026-10-22 ·5 min read

This article discusses the challenges and considerations of using Co­Register­Initialize­Spy for cleaning up unmarshalable delegates in COM. It highlights issues related to thread management and the unpredictability of the unregistration process.

From the article

Another suggestion from Luca Bacci on creating a fake agile wrapper that is technically agile but is not useful outside its home apartment was to use the IInitialize­Spy interface .

Some of the thing that made The Ro­Register­For­Apartment­Shutdown unsuitable also apply to Co­Register­Initialize­Spy . For example, you are required to revoke the spy from the same thread that registered it, which means that we have to remember the original thread so we can somehow get back to executing code on it.

Another problem is explicitly noted in the documentation for Co­Revoke­Initialize­Spy :


Share this resource


Discovered 2026-10-26 Source The Old New Thing Archive 2026-10 →