6

I am trying to include a code snippet in my class XML documentation but the compiler complaining that an xml element is not closed! Here is what I am trying to achieve

/// <summary>
/// Method documentation here...
/// </summary>
/// <remarks>
/// <para>
/// This class should be used as follow:
/// <br/>
/// ************** PROBLEM IN NEXT LINE ********************
/// <c> MyClass class = new MyClass<String>(); </c>
/// </para>
/// </remarks>
public class MyClass<T>{
....
}

I tried to replace the code snippet by /// <c> MyClass class = new MyClass{String}(); </c>

Any one has experienced this before?

Thanks for your help

2
  • This was asked and answered at stackoverflow.com/questions/532166/… Commented Feb 23, 2012 at 12:21
  • @KAJ since OP updated and corrected a copy/paste error I agree and voted to close as duplicate. Commented Feb 23, 2012 at 12:30

4 Answers 4

8

In xml documentation, you have to replace the triangular braces with curly braces:

 /// <summary>
 /// Calls <see cref="DoSomething{T}"/>.
 /// </summary>
 public void CallsDoSomething()
 {

 }

 public void DoSomething<T>()
 {

 }

The reason you end up forced to do this, it because it genuinely isn't well formed xml if you allow triangular braces outside of element markup.

The replace you tried is correct.

Sign up to request clarification or add additional context in comments.

1 Comment

yes - you can do that as well - although it makes the code documentation itself less readable IMHO.
5

You didn't close the Remarks element in the 4th line, it might be complaining about that, just at the wrong line number.

Also, with examples containing generics, it picks up List<string> as the text literal List followed by an unclosed string XML element. The easiest way around this is to do List &amp;lt;string&amp;gr; which when parsed produces List<string> without being an XML element.

The C# compiler team added { and } as replacements for that, so you can just do List{string} and it will be processed into <>'s.

1 Comment

Sorry, that was a copy/paste issue. Just added the closing tag for remarks.
3

A couple of things:

  1. Escape your < and > characters by replacing them with &lt; and &gt;.
  2. Close your XML <remarks> section with a </remarks>
  3. When you do decided to reference a generic in a tag (i.e. <see ... />, <seealso ... />, etc.) then you would do so like the following: <see cref="SomeMethod{T}(T value)" />. Never specify a concrete type in the reference (that is, don't do <see cref="SomeMethod{String}(String value)" />).

Here is a fixed version of your XML Comments:

/// <summary>
/// Method documentation here...
/// </summary>
/// <remarks>
/// <note type="implementsinfo">
///     <para>This class should be used as follow:</para>
///     <para><c>MyClass class = new MyClass&lt;string&lt;();</c></para>
/// </note>
/// </remarks>
public class MyClass<T>
{
    ....
}

1 Comment

Thanks for the quick response. I will go for using {} instead of &lt; and &lt;
2

Your <remarks> are never closed.

Replacing the angular braces like you already tried is also needed.

2 Comments

Sorry, that was a copy/paste issue. Just added the closing tag for remarks.
In that case KAJ is right and using curly braces will fix your issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.