me.at.coding
me.at.coding

Reputation: 17744

Visual Studio XML comments (summary) and special characters

I have a method in a C# / Wpf project and I'd like to comment / document it using the XML comments like this

    /// <summary>
    /// Initialises Drag & Drop
    /// </summary>
    void initDragDrop()
    {

    }

When I now use this method somewhere in my project and hover the mouse over it, I get the message "XML comment contains invalid XML: At this place, no spaces are allowed" (I translated the text after the colon manually to english, so it may not be literally in your visual studio). I found out the problem is the "&" sign, if I remove it, it works fine. But I want to keep it, so how to I escape it in the XML summary? I tried "\&" but this isn't working.

Thanks for any hint!

Upvotes: 17

Views: 6020

Answers (1)

Joel Coehoorn
Joel Coehoorn

Reputation: 416081

Remember that the & character has special meaning in xml (the start of an entity). You need to write your comment like this instead (annoying, I know):

/// <summary>
/// Initialises Drag &amp; Drop
/// </summary>
void initDragDrop()
{

}

I might be wrong on this next point, but I don't think you can even use a CDATA section to avoid the entity, because it breaks the comments. You must type out the entire &amp; entity.

Upvotes: 21

Related Questions