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.
Even when I'm executing it in Release mode, it pays attention to breakpoints. But during step by step execution the indicator steps into one line of an if
branch although the condition evaluates to false
, and then continues to run behind the branch as expected (ironically, the line the indicator assumes would be executed is an exit
statement, so it is definitely not 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.
However, when I switch the start configuration to "Debug x64" and try to run the project, it gives me a "Bad Image" error:
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.
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:
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
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:
$(DebugCppRuntimeFilesPath)
macro, which is not part of any entry in the "VC++ directories" settings.$(DebugCppRuntimeFilesPath)
macro evaluates to "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Redist\MSVC\14.16.27023\debug_nonredist\x64", when the dll is in "...\14.16.27012\...". The directory "14.16.27023" does not exist.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.
Update: 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.
Hans Passant suggested that the error code means the dll file in C:\Windows\System32\
is broken.
I checked that indeed the dll in System32
(981,552 bytes, unsigned, only some entries on the file properties details tab filled) is different from the one distributed with VS (981,744 bytes, signed, full information on the file properties details tab). Hence I decided to replace the current "msvcp140d.dll" in System32
by renaming it into "msvcp140d_orig.dll" and copying the one from C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Redist\MSVC\14.16.27012\debug_nonredist\x64\Microsoft.VC141.DebugCRT\
over.
Now debugging works.
I am not 100% convinced VS should use that file opposed to the one distributed with the workload in the first place, but at least my problem is solved and I can debug the code.