Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
XML comment on 'construct' has syntactically incorrect cref attribute 'name'
Compiler warning CS1574 occurs when a cref attribute in an XML documentation comment refers to a code element that the compiler cannot resolve, or contains invalid syntax.
Common causes
- Typographical error in symbol name: The member, type, or namespace name is misspelled.
- Missing namespace or using directive: The referenced type resides in another namespace that isn't imported via a
usingdirective in the file. - Invalid generic syntax: Generic types in XML
crefattributes should use braces ({}) rather than angle brackets (<>), because unescaped angle brackets conflict with XML syntax (for example,List{T}instead ofList<T>). - Incorrect member signature: When disambiguating overloaded methods, parameter type signatures must match existing method overloads.
- Inaccessible symbol: The referenced member or type is private or internal to another assembly and cannot be referenced.
Example
The following sample generates CS1574:
// CS1574.cs
// compile with: /W:1 /doc:comments.xml
using System;
/// <summary>
/// Sample class demonstrating XML documentation.
/// </summary>
/// <exception cref="System.Console.WriteLin">An exception class.</exception> // CS1574: 'WriteLin' does not exist
public class Example
{
/// <summary>
/// Processes a collection of items.
/// Refer to <see cref="System.Collections.Generic.List<int>"/> for details. // CS1574: invalid angle brackets in XML
/// </summary>
public void ProcessItems()
{
}
}
How to fix this warning
To resolve CS1574:
- Correct typos: Verify that the member or type name is spelled correctly (for example, change
WriteLintoWriteLine). - Use braces for generic types: Replace angle brackets with curly braces in generic type and method references (for example, use
cref="System.Collections.Generic.List{T}"orcref="System.Collections.Generic.Dictionary{TKey, TValue}"). - Specify parameter types for overloads: When referencing a specific overload, supply the parameter types within parentheses (for example,
cref="Console.WriteLine(string)"). - Add missing using directives or qualify names: Add the appropriate
usingdirective or fully qualify the type name (for example,cref="System.Text.StringBuilder").
The following corrected example compiles with zero warnings:
using System;
using System.Collections.Generic;
/// <summary>
/// Sample class demonstrating XML documentation.
/// </summary>
/// <exception cref="InvalidOperationException">Thrown when state is invalid.</exception>
public class Example
{
/// <summary>
/// Processes a collection of items.
/// Refer to <see cref="List{T}"/> for details.
/// </summary>
public void ProcessItems()
{
}
}
How to suppress this warning
If you cannot update the comments immediately or want to suppress the warning temporarily:
In source code: Use
#pragma warning disable CS1574:#pragma warning disable CS1574 /// <see cref="LegacyOrExternalSymbol" /> #pragma warning restore CS1574In the project file: Add CS1574 to
<NoWarn>:<PropertyGroup> <NoWarn>$(NoWarn);CS1574</NoWarn> </PropertyGroup>