4

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#?

Nicolas Raoul
  • 58,567
  • 58
  • 222
  • 373
  • 3
    it works fine for me in VS2008 and VS 2010 with 0 error 0 warning and 0 message! where are you getting this message: `XML comment is not placed on a valid language element main` – Sanjeev Rai Jul 18 '13 at 10:18
  • Certain language elements aren't aloud to have xml documentation such as Namespaces and obviously in this case main methods also. http://msdn.microsoft.com/en-us/library/d3x6ez1z(v=vs.90).aspx I would suggest if you wanted to comment it just use double quotes // – DotNetRussell Jul 18 '13 at 10:20
  • @SanjeevRai: The error appears in the `Error list` window of Visual Studio 2010 Professional. – Nicolas Raoul Jul 18 '13 at 10:22
  • @AMR: Could you please propose this as an answer? This is probably what I will end up doing. – Nicolas Raoul Jul 18 '13 at 10:22
  • I guess it should be warning as error. – Sandy Jul 18 '13 at 10:23

3 Answers3

2

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.

Sandy
  • 11,332
  • 27
  • 76
  • 122
2

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.

Nicolas Raoul
  • 58,567
  • 58
  • 222
  • 373
DotNetRussell
  • 9,716
  • 10
  • 56
  • 111
1

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.

Saurabh
  • 95
  • 1
  • 1
  • 8