title: C++ debugging: MSVCP140D.dll is either not designed to run on Windows
body: <p>I am trying to debug a C++ program I took the source code over for in Visual Studio 2017 Professional. I can build the application in "Release x64" configuration and it executes fine.</p>
  
  <p>Even when I'm executing it in <em>Release</em> mode, it pays attention to breakpoints. But during step by step execution the indicator steps into one line of an <code>if</code> branch although the condition evaluates to <code>false</code>, and then continues to run behind the branch as expected (ironically, the line the indicator assumes would be executed is an <code>exit</code> statement, so it is definitely <em>not</em> executed). I guess some auto-indentation caused the debug symbols to become out of sync with the source. That's why I'd like to refresh the symbols or execute the code in the actual "Debug" configuration.</p>
  
  <p>However, when I switch the start configuration to "Debug x64" and try to run the project, it gives me a "Bad Image" error:</p>
  
  <blockquote>
    <p>C:\WINDOWS\SYSTEM32\MSVCP140D.dll is either not designed to run on Windows or it contains an error. Try installing the program again using the original installation media or contact your system administrator or the software vendor for support. Error status 0xc000012f.</p>
  </blockquote>
  
  <p>From what I know "MSVCP140D" stands for the "Microsoft Visual C++ v140 Debug" version of the dll. The dll is not missing, in fact I have it at 6 locations on my machine:</p>
  
  <pre class="lang-none prettyprint-override"><code>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Redist\MSVC\14.16.27012\debug_nonredist\x64\Microsoft.VC141.DebugCRT\msvcp140d.dll
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Redist\MSVC\14.16.27012\debug_nonredist\x86\Microsoft.VC141.DebugCRT\msvcp140d.dll
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Redist\MSVC\14.16.27012\onecore\debug_nonredist\x64\Microsoft.VC141.DebugCRT\msvcp140d.dll
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Redist\MSVC\14.16.27012\onecore\debug_nonredist\x86\Microsoft.VC141.DebugCRT\msvcp140d.dll
  C:\Windows\System32\msvcp140d.dll
  C:\Windows\SysWOW64\msvcp140d.dll
  </code></pre>
  
  <p>The "Desktop development with C++" workload is said to be fully installed by VS Installer (that claims itself up-to-date as version 1.18.1100.314). I'm usually programming in C#, so I'm not familiar with the way the project settings interact, and I noticed several things, but I'm not sure if any of them have to do with my problem:</p>
  
  <ol>
  <li>The platform tool set is "Visual Studio 2017 (<strong>v141</strong>)".</li>
  <li>The only macro containing a path that looks remotely like one of the 4 "redist" paths mentioned above is the <code>$(DebugCppRuntimeFilesPath)</code> macro, which is not part of any entry in the "VC++ directories" settings.</li>
  <li>That <code>$(DebugCppRuntimeFilesPath)</code> macro evaluates to "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Redist\MSVC\14.16.270<strong>23</strong>\debug_nonredist\x64", when the dll is in "...\14.16.270<strong>12</strong>\...". The directory "14.16.270<strong>23</strong>" does not exist.</li>
  </ol>
  
  <p>Point 3 looks like the most promising hint to me, but I have no idea where that higher version number is coming from, where to change or influence it in the project or installation, etc.</p>
  
  <p><strong>Update:</strong> I also tried downloading the VS 2019 installer now (version 2.0.3297.403) and see if that offers any updates to the VC++ workloads, but apparantly it doesn't.</p>