title: Visual Studio debugger stops hitting breakpoints in mixed debugging mode
body: <p>I have a severe problem with mixed debugging in MSVC2013. After a call to a COM method from a native C++ DLL, debugger does not stop at breakpoints any more.</p>
  
  <h2>Code structure</h2>
  
  <p><a href="https://i.stack.imgur.com/W1OQH.png" rel="noreferrer"><img src="https://i.stack.imgur.com/W1OQH.png" alt="Scheme"></a></p>
  
  <p>The picture above presents the overall structure of the code.</p>
  
  <p>I have a single solution with about ten C# projects, about fifty C++ native projects, and one C++/CLI project serving as a bridge between managed and native worlds. Startup project is a C# WPF project (<code>GUI Application</code>), it calls C++/cli project (<code>Bridge</code>) internally, which in turn calls various native C++ Dlls (<code>Various libraries</code>). Alternatively, I can make a C++ console application (<code>Service console app</code>) as startup project for testing purposes only.</p>
  
  <p>I have implemented a library to import some information from <a href="https://en.wikipedia.org/wiki/Autodesk_Inventor" rel="noreferrer">Autodesk Inventor</a> document files. Inventor Apprentice COM server (<code>Inventor Apprentice</code> on picture) is used to achieve it, which was freely downloaded alongside with <a href="http://usa.autodesk.com/adsk/servlet/pc/item?siteID=123112&amp;id=22976407" rel="noreferrer">Inventor View 2015</a>. As a first step, the import was implemented in a standalone native C++ console application, and everything worked fine. Then it was adapted to be used in the whole infrastructure as a native C++ dll (<code>Import library</code>), and the debugging hell started.</p>
  
  <h2>Symptoms</h2>
  
  <p><strong>"debugging broken".</strong> In a debug build, after calling the following COM method in <code>Import library</code>:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>auto pComponentDefinitions = pDocument-&gt;GetComponentDefinitions();
  </code></pre>
  
  <p>breakpoints in C++ code are no longer hit. Even if I set a breakpoint in the code of another DLL, it is not hit. Breakpoints still visualize as full red circles, so this is not related to PDB issues.
  The application itself continues to execute, and some time later I can see the correct results of data import visible in GUI, meaning that <code>Import library</code> has executed correctly. After that, I can pause the <code>GUI Application</code> with Break All button, in which case the main thread is shown stuck deeply inside one of the Inventor's dlls (rse.dll), which cannot be true because that thread has finished import and has even returned correct results.</p>
  
  <p>In the Output window, I can see the following messages, appearing during the problematic COM method call (access violations seem to be normal in Apprentice):</p>
  
  <pre class="lang-none prettyprint-override"><code>First-chance exception at 0x000007FEDD451F0C (rse.dll) in GUIApplication.exe: 0xC0000005: Access violation writing location 0x000007FFFDE3AFCC.
  The Common Language Runtime cannot stop at this exception. Common causes include: incorrect COM interop marshalling and memory corruption. To investigate further use native-only debugging.
  First-chance exception at 0x000007FEDD455F6C (rse.dll) in GUIApplication.exe: 0xC0000005: Access violation writing location 0x000007FFFDE3EE6C.
  </code></pre>
  
  <p>I have tried to embed breakpoints into the code at the moment of compilation, by inserting <a href="https://msdn.microsoft.com/en-us/library/f408b4et.aspx" rel="noreferrer">__debugbreak()</a> before and after the problematic import code. The first one is hit (if debugging is not yet broken), but the second one is not. On the other hand, debugger clearly notices it, because it writes the following message to Output window:</p>
  
  <pre class="lang-none prettyprint-override"><code>The process hit a breakpoint the Common Language Runtime cannot continue from.
  This may be caused by an embedded breakpoint in the native runtime or a breakpoint set in a can't-stop region.
  To investigate further, use native-only debugging.
  </code></pre>
  
  <p>Google gives no results at all for this diagnostic message. It sounds like MSVC thinks it is debugging managed code, which is actually native.</p>
  
  <p><strong>"crashes in call".</strong> In case of release build, running the application in mixed debugging mode results in a crash inside rse.dll during the problematic COM call. </p>
  
  <h2>Reproducibility</h2>
  
  <p>I use MSVC 2013 update 4. Project is built in x64 mode. Net Framework v4.0 is used. Inventor Apprentice from Inventor 2015 is used.
  Experimentation shows that:</p>
  
  <ol>
  <li>Everything is OK when no debugger is attached.</li>
  <li>Everything works correctly (including debugging), when native-only debugging is used (either via <code>Service console app</code> or after attaching to already running process in native only mode).</li>
  <li>In mixed (i.e. native + managed) debugging mode the problem reproduces regardless of whether <code>GUI application</code> was started with debugging or debugger was attached to a working process.</li>
  <li>There is a problem both in debug and release modes, but it acts differently. In debug build crazy debugging issues arise ("debugging broken"), but in release it simply crashes somewhere inside ("crashes inside").</li>
  </ol>
  
  <p>Full list of runs performed can be seen <a href="https://docs.google.com/document/d/1nzMSU37gaVEbT43CY09gzPxzy4NwnhSzFAnjo_2tmQM/edit?usp=sharing" rel="noreferrer">here</a>.</p>
  
  <h2>The main question</h2>
  
  <p>Has anyone seen similar behavior before? What may be the cause of such behavior? Is there a way to fix it?</p>