ALT+TAB duplicates custom panes in Excel

Sep 21, 2011 at 8:30 PM

To reproduce:

  1. Run Excel with the addin that registers custom pane.
  2. Open any excel file
  3. Open another excel file
  4. ALT+TAB between them.
  5. Every time a window becomes visible another panel is created

The cause of the problem seems to be in OneToManyCustomTaskPaneAdapter:

 public bool ViewRegistered(object view)
    return _customTaskPanes.Any(c => c.Window == view);
"==" here will always be false (easy to see in Debugger: c.Window == c.Window will return false in Immediate Window, also c.Window.GetHashCode() will give a new value every time you call it)

What's interesting this seems to affect only Excel (at least when I'm running an example for Word the equality check works as expected.

Is there a better solution than interrogating the window object via Reflection? (e.g. to get the filename associated with it)

Nov 4, 2011 at 3:12 AM

Interesting.. it seems that excel gives a new RCW, while word reuses it..

I will see if I can have a quick look over the weekend. I have been busy with other projects for a while now, and probably should give this some love