Question

In C# I have written an XML comment for the main method:

/// <summary>
/// Some comment.
/// </summary>
public static void Main(string[] args)
{

But Visual Studio warns me against it:

XML comment is not placed on a valid language element main

What is the recommended way to comment on the main method in C#?

Was it helpful?

Solution

Certain language elements aren't allowed to have xml documentation such as Namespaces and obviously in this case main methods also. The Documentation says this and also has some links that show other XML do's and don'ts.

The only hacky answer I could possibly suggest is if you wanted to comment it just use double quotes // instead of triples. The triples are processed into documentation for the class and is likely causing background issues.

OTHER TIPS

I think you need to place comments for parameters also.

/// <summary>
/// 
/// </summary>
/// <param name="args"></param>
static void Main(string[] args)
{

I think this is what VS is looking for. After writing the method, just type /// above the method. Atleast it gives no error/warning in my Visual Studio.

Hope it helps.

I would like to add a suggestion to it. Go to the project's property -> Build and then mark the check box stating XML documentation file before you start writing the XML documentation. This will help you while writing the XML tags. If you place an invalid XML tag, say above namespace then the VS will prompt stating: XML comment is not placed on a valid language element.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top