Quantcast
Channel: Visual Studio Integrate forum
Viewing all articles
Browse latest Browse all 4410

VS2010 - Subscription to DTE events doesn't seem to work - Events don't get called

$
0
0

I've made an extension inside a package and I am calling the following code (occurs when a user presses a button in the toolbar):

 

DocumentEvents documentEvents = (DTE2)GetService(typeof(DTE));<br/>
_dte.Events.DebuggerEvents.OnEnterBreakMode += DebuggerEvents_OnEnterBreakMode;
_dte.Events.DebuggerEvents.OnEnterDesignMode += DebuggerEvents_OnEnterDesignMode;
_dte.Events.DebuggerEvents.OnContextChanged += DebuggerEvents_OnContextChanged;
_dte.Events.DocumentEvents.DocumentSaved += new _dispDocumentEvents_DocumentSavedEventHandler(DocumentEvents_DocumentSaved);
_dte.Events.DocumentEvents.DocumentOpened += new _dispDocumentEvents_DocumentOpenedEventHandler(DocumentEvents_DocumentOpened);void DocumentEvents_DocumentOpened(Document Document)
    {
    }void DocumentEvents_DocumentSaved(Document Document)
    {
    }void DebuggerEvents_OnEnterBreakMode(dbgEventReason Reason, ref dbgExecutionAction ExecutionAction)
    {
    }void DebuggerEvents_OnContextChanged(Process NewProcess, Program NewProgram, Thread NewThread, StackFrame NewStackFrame)
    {
    }privatevoid DebuggerEvents_OnEnterDesignMode(dbgEventReason reason)
    {
    }

The first and the major problem is that the subscription to the event doesn't work. I've tried:

  • Opening new documents
  • Detaching from debug (thus supposedly triggering OnEnterDesignMode
  • Saving a document

None of these seem to have any effect and the callback functions were never called.

The second issue is that the subscription to the event line works (the subscription itself, the callback doesn't work as described above) USUALLY but after a while running the subscription line, e.g:

_dte.Events.DebuggerEvents.OnEnterBreakMode -= DebuggerEvents_OnEnterBreakMode;<br/>

Causes an exception:

Exception occured!
System.Runtime.InteropServices.InvalidComObjectException: COM object that has been separated from its underlying RCW cannot be used.
   at System.StubHelpers.StubHelpers.StubRegisterRCW(Object pThis, IntPtr pThread)
   at System.Runtime.InteropServices.UCOMIConnectionPoint.Unadvise(Int32 dwCookie)
   at EnvDTE._dispDebuggerEvents_EventProvider.remove_OnEnterDesignMode(_dispDebuggerEvents_OnEnterDesignModeEventHandler A_1)

Any ideas will be welcome.

Further details:
.NET version: 4
Visual studio 2010
Windows 7 Ultimate

Thanks,
Vitaly

Viewing all articles
Browse latest Browse all 4410

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>