[VS2022][.Net 6.0] Can I see the callstack of program.cs main method invoker?

Vishnu Gopalakrishnan 126 Reputation points
2022-08-11T15:57:43.267+00:00

I know Starting with .NET 6, the project template for new C# console apps generates the following code in the Program.cs file:
Console.WriteLine("Hello, World!");
// See https://aka.ms/new-console-template for more information

I wish to see the call stack source code above. i.e the main method starting. Is it possible?
Even after I enabled stepping into the .NET Framework source, I could not see the source file.
In the disassembly view of the call stack, the Go to the source file is disabled for this.

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,344 questions
.NET CLI
.NET CLI
A cross-platform toolchain for developing, building, running, and publishing .NET applications.
321 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,196 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,117 questions
Visual Studio Debugging
Visual Studio Debugging
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Debugging: The act or process of detecting, locating, and correcting logical or syntactical errors in a program or malfunctions in hardware. In hardware contexts, the term troubleshoot is the term more frequently used, especially if the problem is major.
935 questions
0 comments No comments
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 54,866 Reputation points
    2022-08-11T17:12:59.403+00:00

    there is no call stack. you are at the top of the stack. here is the generated IL code:

    .method private hidebysig static void  '<Main>$'(string[] args) cil managed  
    {  
      .entrypoint  
      // Code size       12 (0xc)  
      .maxstack  8  
      IL_0000:  ldstr      "Hello, World!"  
      IL_0005:  call       void [System.Console]System.Console::WriteLine(string)  
      IL_000a:  nop  
      IL_000b:  ret  
    } // end of method Program::'<Main>$'  
      
      
    

    notice the .entrypoint that defines this as the code to call at startup.

    the program compiled to a .net dll. the generated hosting program (<name>.exe) is a C/C++ program that loads the dll, and calls the program code passing args. see:

    https://github.com/dotnet/runtime/blob/main/docs/design/features/native-hosting.md

    note: for min api, the C# compiler generates the main(string[] args) wrapper


0 additional answers

Sort by: Most helpful