Fog Creek Software
Discussion Board




Welcome! and rules

Joel on Software

VS Automation sadness/insanity

I have a very simple add-in that checks if a project item being added is a .cs file, and if so, adds some things to the code structure.  It works well, except for the fact that, well, it doesn't work anymore.

My code:

public void OnStartupComplete(ref System.Array custom)
{
  // Get an instance of the currently running Visual Studio .NET IDE.
  ProjectItemsEvents CSharpProjectItemsEvents = (ProjectItemsEvents)applicationObject.Events.GetObject("CSharpProjectItemsEvents");
  CSharpProjectItemsEvents.ItemAdded += new _dispProjectItemsEvents_ItemAddedEventHandler(Connect_ItemAdded);
}

...

public void Connect_ItemAdded(ProjectItem target)
{
  //do FileCodeModel stuff here
}

The ItemAdded event handler never fires!  I swear that this was working before I went to lunch... any ideas?

Greg Hurlman
Monday, August 16, 2004

FYI: The "contractor" you don't get along with was mucking around your workstation while you were at lunch.

Roger
Monday, August 16, 2004

Reboot your workstation. It'll probably work after that.

Mike
Monday, August 16, 2004

It seems that my CSharpProjectItemsEvents variable was being garbage collected, and thus the event hook was lost.  I moved it to a class-level member, and it worked.

Sigh.

Greg Hurlman
Tuesday, August 17, 2004

*  Recent Topics

*  Fog Creek Home