4

I am developing an Extension (VSPackage), I am subscribing to 2 of the Debugger events in the constructor of VSPackage.cs

public sealed class ComboBoxPackage : Package
{
....
 public ComboBoxPackage()
        {
            Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering constructor for: {0}", this.ToString()));
            _dte = (DTE)Package.GetGlobalService(typeof(DTE));
            _events = _dte.Events;
            _debuggerEvents = _events.DebuggerEvents;

            _debuggerEvents.OnEnterRunMode += _debugEvents_OnEnterRunMode;
            _debuggerEvents.OnContextChanged +=_debuggerEvents_OnContextChanged;      
        }

        void _debuggerEvents_OnContextChanged(EnvDTE.Process NewProcess, Program NewProgram, Thread NewThread, EnvDTE.StackFrame NewStackFrame)
        {
            throw new NotImplementedException();
        }


        private void _debugEvents_OnEnterRunMode(dbgEventReason Reason)
        {
            return;
        }

}

when I'm running it ( strating run an application ) only _debuggerEvents_OnContextChanged is called, and _debugEvents_OnEnterRunMode is not called.

if I did the same with Addin project all works fine.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Ruthg
  • 241
  • 2
  • 4
  • 11

1 Answers1

2

I hope it's not late enough... Are you keeping a reference to the DebuggerEvents directly from your code and handling the event from there.

It happened the same to me, and I fixed it on this way.

  • Had to read it a few times, but it actually solves the problem. Just to clarify for other people with the same issue. The solution is to keep a reference to a `DebuggerEvents` object obtained from `dte.Events` as long as you want the event to be fired. Otherwise, it is probably consumed by the Garbage Collector. – Estiny Feb 21 '16 at 14:03