Note that there are some explanatory texts on larger screens.

plurals
  1. POSubscription to DTE events doesn't seem to work - Events don't get called
    text
    copied!<p>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):</p> <pre><code>DocumentEvents documentEvents = (DTE2)GetService(typeof(DTE)); _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) { } private void DebuggerEvents_OnEnterDesignMode(dbgEventReason reason) { } </code></pre> <p>The first and the major problem is that the subscription to the event doesn't work. I've tried:</p> <ul> <li>Opening new documents </li> <li>Detaching from debug (thus supposedly triggering OnEnterDesignMode </li> <li>Saving a document</li> </ul> <p>None of these seem to have any effect and the callback functions were never called.</p> <p>The second issue is that the subscription to the event line works USUALLY (the subscription itself, the callback doesn't work as described above) but after a while running the subscription line, e.g:</p> <pre><code>_dte.Events.DebuggerEvents.OnEnterBreakMode -= DebuggerEvents_OnEnterBreakMode; </code></pre> <p>Causes an exception:</p> <pre><code>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) </code></pre> <p>Any ideas will be welcome</p> <p>Thanks! Vitaly</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload