Skip to content

Extra async Main method in output #10

@goojal

Description

@goojal

Decompiling a Program with an async Main method generates an extra method (named u003cMainu003e in example below) that calls the other Main.

Input Program.cs:

namespace Sample3
{
    internal class Program
    {
        async static Task Main(string[] args)
        {
            Console.WriteLine("Hello, World!");
            await sleep();
        }
        async static Task sleep()
        {
            await Task.Delay(1000);
        }
    }
}

Output Program.cs:

using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;

namespace Sample3
{
	[Nullable(0)]
	[NullableContext(1)]
	internal class Program
	{
		public Program()
		{
		}

		[DebuggerStepThrough]
		// <Main>
		private static void u003cMainu003e(string[] args)
		{
			Program.Main(args).GetAwaiter().GetResult();
		}

		private static async Task Main(string[] args)
		{
			Console.WriteLine("Hello, World!");
			await Program.sleep();
		}

		private static async Task sleep()
		{
			await Task.Delay(0x3e8);
		}
	}
}

csproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

</Project>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions