Sample code:
```c#
using System.Threading.Tasks;
class C
{
static async Task Main()
{
}
}
When I build this with C# 7.0, I see two errors:
error CS5001: Program does not contain a static 'Main' method suitable for an entry point
error CS8107: Feature 'async main' is not available in C# 7.0. Please use language version 7.1 or greater.
``
for some reason I'm only seeing the second one in the build output, not in the IDE or the error list. It would be helpful if it did show up in the IDE on theMain` token so that we could provide a code fix to upgrade the project.
The Roslyn API that implements compilation logic is lazy and layered. There is a parsing layer, a binding layer, multiple layers of lowering/transformation and finally emitting. Each layer could produce diagnostics, but only if you pull on it (that's the lazy part).
Most errors are reported during parsing or binding, but there are a few errors than can only be reported later (during emitting, as is the case of bad entry point). The IDE pulls no further than the first two layers, since that produces the vast majority of diagnostics and much reduces the computation costs (compared to going all the way to emitting).
From my understanding, emitting the final binary (Emit API) is the only API that causes the entry point to be realized. So I don't see how this diagnostic could be produced in a lower layer...
Relates to https://github.com/dotnet/roslyn/issues/1400
There is another issue discussing this. I'll try to dig it up.
Tagging @TyOverby in case anything to add.
Thanks. I suppose we could create a special analyzer to report this instead of looking for a compiler error to make UpgradeProject work here.
I think UpgradeProject already kicks in once the diagnostic is produced, ie. the first time the project is built.
@jcouv It's not working for me even after I build.
I don't know if this is related, but I'm seeing a really interesting behavior in the error list when filtering:



If I choose IntelliSense Only, the error list is empty.
If I choose Build Only, I get both errors as expected.
But If I select Build + IntelliSense, I only get one of them.
Regardless of that, since this is a build error there is no squiggle in the editor and no code fix available.
I just ran into this, @jcouv @heejaechang isn't this the Error List provider filtering this out? We need to add this to list of codes that get shown under IntelliSense?
Not an expert on this, but I'm guessing this is a little tricky because this error is only produced via command-line but other instances of CS8107 are produced "live", so it might not just be as simply as excluding it from the list of supported error codes.
Ah, I just read what @jcouv pointed to - yes it's basically a dupe of https://github.com/dotnet/roslyn/issues/1400, and I'll dupe it as such.
I'm re-opening this issue, since #1400 covers a broader issue.
The problem with the "async Main" diagnostic was reported by multiple users, so we should consider fixing it separately/sooner if needed.
From discussion in https://github.com/dotnet/roslyn/pull/30380 (a PR proposing an IDE-level approach to fix this) we leaned towards fixing this at the compiler-level instead. The proposal would be to include this diagnostic in the regular diagnostics (ie. not require Build/emit to produce it). When making this change, we'll need to be careful this doesn't cause performance problem, but we have reasons to believe it should not cause much adverse impact.
Most helpful comment
I'm re-opening this issue, since #1400 covers a broader issue.
The problem with the "async Main" diagnostic was reported by multiple users, so we should consider fixing it separately/sooner if needed.
From discussion in https://github.com/dotnet/roslyn/pull/30380 (a PR proposing an IDE-level approach to fix this) we leaned towards fixing this at the compiler-level instead. The proposal would be to include this diagnostic in the regular diagnostics (ie. not require Build/emit to produce it). When making this change, we'll need to be careful this doesn't cause performance problem, but we have reasons to believe it should not cause much adverse impact.