Edit

Compiler Warning (level 1) CS1574

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

  1. Typographical error in symbol name: The member, type, or namespace name is misspelled.
  2. Missing namespace or using directive: The referenced type resides in another namespace that isn't imported via a using directive in the file.
  3. Invalid generic syntax: Generic types in XML cref attributes should use braces ({}) rather than angle brackets (<>), because unescaped angle brackets conflict with XML syntax (for example, List{T} instead of List<T>).
  4. Incorrect member signature: When disambiguating overloaded methods, parameter type signatures must match existing method overloads.
  5. 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 WriteLin to WriteLine).
  • 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}" or cref="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 using directive 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 CS1574
    
  • In the project file: Add CS1574 to <NoWarn>:

    <PropertyGroup>
      <NoWarn>$(NoWarn);CS1574</NoWarn>
    </PropertyGroup>
    

See also