Version Used:
2017.3
Steps to Reproduce:
Run this code:
[STAThread]
static async Task Main(string[] args) {
Console.WriteLine(System.Threading.Thread.CurrentThread.ApartmentState);
}
Expected Behavior:
I expect the thread to be STA.
Actual Behavior:
The thread is MTA.
When I look at the code in JustDecompile, this is what I see (You'll notice that the [STAThread] does not get copied to the "real" main:
````
private static void
{
Program.Main(args).GetAwaiter().GetResult();
}
[STAThread]
private static async Task Main(string[] args)
{
Program.<Main>d__0 variable = null;
AsyncTaskMethodBuilder asyncTaskMethodBuilder = AsyncTaskMethodBuilder.Create();
asyncTaskMethodBuilder.Start<Program.<Main>d__0>(ref variable);
return asyncTaskMethodBuilder.Task;
}
````
FYI. In addition to this, there is also a more general issue for it not being respected in .NET Core: https://github.com/dotnet/coreclr/issues/13688
There was also some discussion of this issue (async main) here: https://github.com/dotnet/csharplang/issues/97
FYI @TyOverby
As mentioned in https://github.com/dotnet/csharplang/issues/97, this was explicitly considered and rejected by LDM. In addition, it sounds as though putting the attribute on the generated main method is not sufficient, anyway.
Regardless, this needs to be taken through the dotnet/csharplang repo and LDM before we'd consider a compiler change here.