Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

508
Visualizações
Unable to properly step through code in static constructor (VS2019, C#, .NET 4.7.2)

I am trying to step through the code of a static constructor while in break mode.

The project is C#/.NET 4.7.2/64-bit/WinForms. Visual Studio version is 2019 16.9.4 Community.

Visual Studio correctly breaks when it gets to the breakpoint set in the static constructor. I can then step through the code using the "Step Into" command (F11). As you can see, the static constructor calls a static method which does the heavy work.

The code contains a loop that should iterate 10 times. I should be able to step through all iterations. Instead, after the first iteration, debugging suddenly jumps to -- or "resumes" -- at some much later point, back in the calling class (or more accurately, the class that triggered the CLR to execute the static constructor). So I am unable to step through the remaining 9 iterations.

I am confident that all iterations are indeed executed, because I added some debug code to print something every time the finally block is executed. But, I am frustrated that I cannot step through the code. Seems like a VS bug of the ludicrous kind, since it's a pretty fundamental thing to be able to step through code when debugging.

Because the problem is so hard to describe well, I have created an animated GIF to visually show the debug session:

Visual Studio 2019 debug session example

I have searched the web far and wide and I can't find anyone else reporting the kind of issue I am here. Which has me wondering whether I am doing something wrong (e.g. do I need to adjust some debugger settings or something?). Any help or insight is much appreciated.

UPDATE

I cannot reproduce the issue in 32-bit Debug builds. The issue is (so far) only present in 64-bit Debug builds.

HOW TO REPRODUCE

I made a tiny demo project. Feel free to download and try debug for yourself. When the breakpoint is hit, use F11 to step through the code. See if you can get through the loop 10 times ;-)

Debug Test Project (VS2019)

On my end, the issue disappears if I change the build configuration from x64 to Any CPU. So it may be a 64-bit only issue.

The try/finally block really seems to reveal the issue. I'm not sure what other patterns might reveal the issue too.

BUG REPORT FILED

https://developercommunity.visualstudio.com/t/The-debugger-does-not-step-through-a-met/1407274

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

It's a bug in the .NET runtime. You can track the bug here:

https://github.com/dotnet/runtime/issues/52328

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda