Visual Studio 2019 hanging in cout/printf

Tyler 1 Reputation point

When debugging in Visual Studio 2019, any time my program attempts to cout or print it causes the debugger to stall infinitely. If I pause the debugger and look at the main thread, it will always be in 'ucrtbased.dll!write_text_ansi_nolock' once it gets stalled.

When I run the built exe on it's own, it prints to console perfectly fine. The stalling happens while the application is single threaded, just trying to console print out a single line of text with no variables.

How can I fix this, or look inside the above DLL to see what is happening?

A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,445 questions
{count} votes

6 answers

Sort by: Most helpful
  1. Abraham Martin 11 Reputation points

    For what it's worth, I managed to solve this closing VS removing the .vs folder and running VS again. Other times it just stopped the same way it appeared: no code changes, no build, just one debugging session is ok, the next one it stops in the 1st printf. It happens with boost calls to (stream_type::write() -> logging system) too, so I suspect "someone" (SO, antivirus?) is not letting VS to write anything out... just guessing.

    It happens to me in visual studio 2022 too (using 2019 compilers, I have both VS installed).

    2 people found this answer helpful.
    0 comments No comments

  2. Justin Ferguson 5 Reputation points

    I've had this problem intermittently for years across multiple versions of Visual Studio-- its never in a clean-cut example which makes it hard to reproduce and/or report. I've not looked at what's occurring at an assembly level, but its always in a printf/std::cout et al.

    To fix it temporarily, that is to step past the problem until it crops up again-- reboot. To remedy the issue apparently permanently do as suggested by Abraham and delete the .vs folder in the solutions parent directory then restart visual studio.

    1 person found this answer helpful.
    0 comments No comments

  3. Dan Honeycutt 1 Reputation point

    Has anything more developed on this issue? I have the same problem. My version:

    Microsoft Visual Studio Community 2022 (64-bit) - Current
    Version 17.2.6

    Thanks for any help.
    Dan Honeycutt

  4. Minxin Yu 9,361 Reputation points Microsoft Vendor

    delete the .vs folder in the solutions parent directory then restart visual studio.

    It is recommended that the problem be reported to the Developer Community. And it would be helpful to provide a minimal reproducible example.

    0 comments No comments

  5. Igor Polkovnikov 0 Reputation points

    I have the same. VC2022. It hangs in KernelBase WriteFile. After removing .vs it run at least twice fine. Version 17.2.6, x86, Debug

    0 comments No comments