'MSVCP140.dll initialization failed

My application throws this error on the start

Unhandled exception at 0x00007FF8DC378C34 (msvcp140.dll) in TimexLPRService.exe: 0xC0000005: Access violation reading location 0x0000000000000000.

In Stack Frame control I see msvcp140.dll!mtx_do_lock(_Mtx_internal_imp_t *mtx, const xtime *target)

const xtime *target is null (it shows in locals control)

If I start application manually it tells I have error on startup (error code 0xc0000142). I have msvcp140.dll and vcruntime140.dll near the executable

I build my application with Visual Studio 2019 and vcpkg

I want to know how I can debug this problem to understand what went wrong or what possible causes of such problem



Solution 1:[1]

There can be different reasons.

#1 (update)

You may have a null pointer exception somewhere:

Access violation reading location 0x0000000000000000

To fix, try running your code using IDE's debugger, and it should break on the first access violation.

#2

The "MSVCP140.dll" name is shared between multiple versions, for example MSVC 2015 and MSVC 2019.

As long as the latest redist is installed, there should be no problems.

But crashs happen, for example if:

  • Your App was built with MSVC 2019.
  • But an older version is installed on the system (like 2015 redist).
  • Or, the correct redist is installed, but the wrong .dll version is placed beside your executable.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1