Rider incorrectly reports Syntax error for valid XML doc constructor cref references (#ctor)

Rider marks the XML doc comment itself as invalid.

public sealed class Class1
{
   public Class1() { }
}

internal static class ClassDocs
{
   /// <summary>
   /// Dispose a Instance of <see cref="Class1"/>.
   /// </summary>
   /// <seealso cref="Class1.#ctor"/>
   public static extern void Dispose();
}


Rider highlights:
#ctor
with:
Syntax error

The same happens with qualified members:
/// <seealso cref="M:Class1.#ctor"/>

Rider should accept constructor references using:
#ctor
#ctor(System.Int32,System.String)

0
3 comments

Hello Cig,

This is a valid warning, not a false-positive. 

The goal of writing xml documentation is to generate xml documentation. Once you enable “<GenerateDocumentationFile>true</GenerateDocumentationFile>” in .csproj file, you will start getting compiler warnings like this:

1>{path}\Sample.cs(18,24,18,31): warning CS1584: XML comment has syntactically incorrect cref attribute 'Class1.#ctor'
1>{path}\Sample.cs(18,31,18,32): warning CS1658: Identifier expected. See also error CS1001.
1>{path}\Sample.cs(18,31,18,31): warning CS1658: Unexpected character '#'. See also error CS1056.

The syntax you provided M:Class1.#ctor is the resulting string ID produced in the xml documentation file output, but you shouldn't use this for documenting purpose ‘on frontend’ (when writing .cs). Such a syntax isn't valid.

I wasn't able to find exactly statement prohibiting that, but I assume we can trust compiler here. And I found this:

The cref attribute can be attached to any tag to provide a reference to a code element. The documentation generator must verify that this code element exists. If the verification fails, the documentation generator issues a warning. When looking for a name described in a cref attribute, the documentation generator must respect namespace visibility according to using statements appearing within the source code.oi

And if you add “<TreatWarningsAsErrors>true</TreatWarningsAsErrors>” the project will fail to build:

Hope that helps. Have a nice day!

1

Hello World!

on accident i figured out how to link to Constructors. 

    public class foo {
       public sealed class Class1
       {
           public Class1() { }

           public Class1(int a) {
               
           }

           public Class1(bool a, bool b, bool c) {
               
           }
       }

       internal static class ClassDocs
       {
           /// <summary>
           /// Dispose a Instance of <see cref="Class1"/>.
           /// </summary>
           /// <seealso cref="Class1()"></seealso>
           /// <seealso cref="Class1(int)"></seealso>
           /// <seealso cref="Class1(bool,bool,bool)"></seealso>
           public static extern void Dispose();
       }
   }


note that all params of a Constructors need to be entered to be applied corecctly.
Tested on Rider

0

I am happy to hear a solution was found. Thank you for sharing your experience and have a nice day!

0

Please sign in to leave a comment.