JustDecompileEngine icon indicating copy to clipboard operation
JustDecompileEngine copied to clipboard

Extra async Main method in output

Open goojal opened this issue 2 years ago • 0 comments

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>

goojal avatar Jan 31 '24 11:01 goojal