-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Document CS8892 warning #20164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Document CS8892 warning #20164
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1471ded
Document CS8892 warning
Youssef1313 94e6183
Update cs8892.md
Youssef1313 a67700f
Update cs8892.md
Youssef1313 24540fd
Update cs8892.md
Youssef1313 3182085
Update toc.yml
Youssef1313 dcb5fdf
Update cs8892.md
Youssef1313 1be2fa7
Update cs8892.md
Youssef1313 b97730c
Update cs8892.md
Youssef1313 a5b64e1
Update cs8892.md
Youssef1313 36be2d5
Update cs8892.md
Youssef1313 70872a7
Update cs8892.md
Youssef1313 b7ecaa2
Consistency
Youssef1313 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
docs/csharp/language-reference/compiler-messages/cs8892.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| --- | ||
| title: "Compiler warning (level 5) CS8892" | ||
| ms.date: 08/26/2020 | ||
| f1_keywords: | ||
| - "CS8892" | ||
| helpviewer_keywords: | ||
| - "CS8892" | ||
| author: Youssef1313 | ||
| --- | ||
|
|
||
| # Compiler warning (level 5) CS8892 | ||
|
|
||
| Method 'method' will not be used as an entry point because a synchronous entry point 'method' was found. | ||
|
|
||
| This warning is generated on all async entry point candidates when you have multiple valid entry points, where they contain one or more synchronous entry point and one or more asynchronous entry points. | ||
|
|
||
| Because async main was only supported starting with C# 7.1, this warning isn't generated for projects targeting a previous version. | ||
|
|
||
| > [!NOTE] | ||
| > The compiler always uses the synchronous entry point. In case there are multiple synchronous entry points, you get a compiler error. | ||
|
|
||
| ## Example | ||
|
|
||
| The following examples generates CS8892: | ||
|
|
||
| ```csharp | ||
| using System; | ||
| using System.Threading.Tasks; | ||
|
|
||
| public class Program | ||
| { | ||
| // CS8892: Method 'Program.Main()' will not be used as an entry point because a synchronous entry point 'Program.Main(string[])' was found. | ||
| public static async Task Main() | ||
| { | ||
| await Task.Delay(1); | ||
| } | ||
|
|
||
| public static void Main(string[] args) | ||
| { | ||
| Console.WriteLine(2); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## How to fix this warning | ||
|
|
||
| Keep only the intended entry point for your program, and rename the others. | ||
|
|
||
| ```csharp | ||
| using System; | ||
| using System.Threading.Tasks; | ||
|
|
||
| public class Program | ||
| { | ||
| public static async Task SomeOtherNameAsync() | ||
| { | ||
| await Task.Delay(1); | ||
| } | ||
|
|
||
| public static void Main(string[] args) | ||
| { | ||
| Console.WriteLine(2); | ||
| } | ||
| } | ||
| ``` | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.