Compact Framework blocks access to COM Connection Points

0

I've been Googling a lot for this but no one seems to be talking about this issue.

I have a COM component written in C++ that exposes events ("connection points" in COM parlance). This component (a map control) has been used reliably for several years by clients written in C++ and C# on Windows XP/7. It has also been used reliably for several years by clients written in C++ on Windows CE.

However, connection points are broken in the Compact Framework. There was one device on which they work, but on multiple other devices (different builds of WinCE), events spontaneously unsubscribe themselves!

MapControl _ctrl;
_IMapControlEvents_MouseEventEventHandler _temp;

public MapForm()
{
    InitializeComponent();
    _ctrl = new MapControl();
    _ctrl.MouseEvent += (_temp = HandleMouseEvent);
    ...
}
...

At first HandleMouseEvent() is called by _ctrl for every mouse event, but as soon as a garbage collection occurs, the event is unsubscribed and HandleMouseEvent() is no longer called (I confirmed that the event is unsubscribed by editing the ATL code to print "Subscriber removed".)

Unfortunately it is impossible to re-subscribe. For example, if I use code like this:

_testTimer = new Timer();
_testTimer.Interval = 10000;
_testTimer.Enabled = true;
_testTimer.Tick += (s, e) => {
    _ctrl.MouseEvent -= _temp;
    _ctrl.MouseEvent += _temp;
};

This works as long as there is no garbage collection. But after the first GC, _ctrl.MouseEvent -= _temp and _ctrl.MouseEvent += _temp both throw InvalidComObjectException (0x80131527). You can still call methods on _ctrl but events cannot be used.

So, does anyone know a workaround for this issue? (Is anyone else even having this issue?)

Version: \Windows\cgacutil.exe reports Compact Framework [3.5.11125.0]

c#
com
garbage-collection
compact-framework
asked on Stack Overflow Jun 24, 2014 by Qwertie • edited Jun 25, 2014 by Qwertie

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0