I'm building an ArcGIS Engine for 9.3 using VS.NET 2008 (C#). In OnMapReplaced I hook up ActiveView event handlers for ContentsChanged and ItemAdded. Later, adding a newly created raster layer using InsertLayerInGroup causes the ActiveView event handlers to usually (but not always) be unhooked. What would cause this? Why is it inconsistent? What can be done about it?

Attempting to re-hook the ActiveView event handlers results in "COM object that has been separated from its underlying RCW cannot be used". However, I think the fist paragraph is the real issue!

Did some more testing and it appears that adding the new layer was not what caused the events to unhook. Simply turning layers on/off and right-clicking them to show the context menu eventually caused the events to unhook.

So I did some more hunting on the forum here, and found several references to use of static variables. So I made the delegates static variables, and thought I had solved the problem entirely. But a few minutes ago, after a relatively long test session, the ActiveView events became unhooked!