Recently I installed the latest Visual Studio 2022 v17.10 to build my programs, and initially all went well. But after some other program installation, my programs started failing immediately on start where the first std::mutex::lock()
is called with the exception
0xC0000005: Access violation reading location 0x0000000000000000.
and stack trace:
msvcp140.dll!mtx_do_lock(_Mtx_internal_imp_t * mtx, const xtime * target) Line 100 C++
[Inline Frame] my.dll!std::_Mutex_base::lock()
[Inline Frame] my.dll!std::unique_lock<std::mutex>::{ctor}(std::mutex &)
It turned out that the installed application was built in a previous version of Visual Studio 2022, and it silently downgraded C:\Windows\System32\msvcp140.dll
to version 14.34.31931.0
, where the exception happens.
I personally managed to restore normal operation of my programs, by pressing Repair
in Microsoft Visual C++ 2015-2022 Redistributable (x64) - 14.40.33810
, which restored C:\Windows\System32\msvcp140.dll
to version 14.40.33810.0
.
But since this unexpected crash on start-up can easily happen to the users of my program, I would like to ask, is there a way to make the programs built in the latest Visual Studio 2022 compatible with runtimes from previous versions of the same Visual Studio 2022? Or at least how to show meaningful error to the users if the runtime is downgraded for some reason instead of silent application termination.