Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / Extensibility / April 2007

Tip: Looking for answers? Try searching our database.

solution.events don't fire, attempt to re-bind gives interop error

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Kenneth Baltrinic - 05 Apr 2007 00:22 GMT
I am trying to build a fairly simple ( I think ) add-in wherein I need to
handle the SolutionEvents Opened, AfterClosing, ProjectAdded and
ProjectRemoved events.  I have some code that looks like this

public override void OnConnection( object Application , ext_ConnectMode
ConnectMode , object AddInInst , ref Array custom )
{
 //call to base captures Application into VSApplication field
 base.OnConnection( Application , ConnectMode , AddInInst , ref custom );
 VSApplication.Events.SolutionEvents.Opened += new
_dispSolutionEvents_OpenedEventHandler( OnSolutionOpen );
 VSApplication.Events.SolutionEvents.AfterClosing += new
_dispSolutionEvents_AfterClosingEventHandler( OnSolutionClosed );
 VSApplication.Events.SolutionEvents.ProjectAdded += new
_dispSolutionEvents_ProjectAddedEventHandler( OnProjectAdded );
 VSApplication.Events.SolutionEvents.ProjectRemoved += new
_dispSolutionEvents_ProjectRemovedEventHandler( OnProjectRemoved );

}

Problem is that the code above runs fine when the test IDE starts up (add-in
loads on start up).  But when I load a solution into it, the OnSolutionOpen
event handler is never invoked.

More interestingly, if in the test IDE I go to Tools > Add-in Manager and
unload and reload the add-in, I get the following error on the line that
tries to attach to the Opened event:

COM object that has been separated from its underlying RCW cannot be used.

  at System.Runtime.InteropServices.UCOMIConnectionPoint.Advise(Object
pUnkSink, Int32& pdwCookie)
  at
EnvDTE._dispSolutionEvents_EventProvider.add_Opened(_dispSolutionEvents_OpenedEventHandler
A_1)
  at
EnvDTE.SolutionEventsClass.add_Opened(_dispSolutionEvents_OpenedEventHandler
A_1)
  at MyAddin.OnConnection(Object Application, ext_ConnectMode ConnectMode,
Object AddInInst, Array& custom)

Does anyone have any ideas what might be going on here?
Kenneth Baltrinic - 06 Apr 2007 12:35 GMT
I found my problem.  Though I did not find it documented any where, I
noticed that all the examples always captured the SolutionEvents object into
a class variable (field).  The examples keep that reference until it is time
to unhook the events in OnDisconnect and used it there to unhook the events
as well.  Now that I am doing this instead of calling
Application.Events.SolutionEvents every time, all is working correctly.

>I am trying to build a fairly simple ( I think ) add-in wherein I need to
>handle the SolutionEvents Opened, AfterClosing, ProjectAdded and
[quoted text clipped - 38 lines]
>
> Does anyone have any ideas what might be going on here?
Luis Bascones - 11 Apr 2007 13:51 GMT
The object is not kept alive only to un hook the events, but to allow it to
manage the event handling. This obect is not static or global, and as such
it will keep a list of the event listeners as long as it's alive (someone
holds a reference to it). If one doesn't hold on to it, the GC will
eventually get to it and destroy it.

Carlos Quintero's  mztools.com web site has a good pack of info for VS
developers, and this is one of the topics discussed in there. There a lot of
good stuff in there. I can't recommmend it enough.

-LuisB

>I found my problem.  Though I did not find it documented any where, I
>noticed that all the examples always captured the SolutionEvents object
[quoted text clipped - 46 lines]
>>
>> Does anyone have any ideas what might be going on here?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.