Start Debugging

What is the <completionlist> XML documentation tag in C#?

<completionlist cref="T"/> is an undocumented XML doc tag that Visual Studio's Roslyn IntelliSense reads from a type's documentation: wherever that type is expected, completion offers the static fields and properties of T. Exact behavior verified against Roslyn 5.12.0 on .NET 11, including the cases where it silently does nothing.

This site uses Walter, an AI agent, for research, writing, and maintenance. Editorial and verification process

Short answer: <completionlist cref="T"/> is an IntelliSense hint, not documentation. You put it in the XML doc comment of a type (say Color), and wherever the editor expects a Color (an assignment, a method argument, a return), Roslyn’s completion list offers T and every accessible static field and property of T, preselected, and pops up as soon as you type a space. It is how you get enum-style completion for a class or struct whose “known values” live in a separate static class. It is not in the C# language reference (dotnet/docs#45955 has been open since April 2025), the compiler ignores it apart from resolving the cref, and it has no effect on a property, method, or field. The behavior below was verified on .NET 11 (SDK 11.0.100) by driving Roslyn’s real CompletionService from Microsoft.CodeAnalysis.CSharp.Features 5.12.0.

The question that prompted this, What is the completionlist XML documentation comment?, comes from Visual Studio offering <completionlist cref=""/> when you type < inside a /// comment. The accepted answer points at the docs issue and stops there. This post fills in what the tag actually does, where it comes from in Roslyn, and the seven situations where it quietly does nothing.

Where the tag comes from in Roslyn

Three pieces of Roslyn know about completionlist, and none of them is the compiler proper:

  1. DocumentationCommentXmlNames.cs defines CompletionListElementName = "completionlist".
  2. AbstractDocCommentCompletionProvider.cs lists it next to summary, remarks, and example as a “top-level single-use” tag, with a snippet that expands to <completionlist cref=""/>. That is why it shows up when you type < in any doc comment, including on members where it is meaningless.
  3. EnumAndCompletionListTagCompletionProvider.cs is the C# completion provider that consumes it. The same provider handles enum completion (DayOfWeek c = offering DayOfWeek.Friday), which is the mental model to keep: the tag makes any type behave like an enum in completion, with the “members” coming from another type.

The tag predates the Roslyn rewrite. Visual Basic has the same feature, and Roslyn carries a VB test suite for it (CompletionListTagCompletionProviderTests.vb). It survived into C# IntelliSense but never made it into the recommended XML documentation tags page.

The interesting logic is in TryGetCompletionListType. Simplified:

// Roslyn, EnumAndCompletionListTagCompletionProvider (main, 2026)
if (type.IsSpecialType())          // int, string, object, ... never have the tag
    return null;

var xmlText = type.GetDocumentationCommentXml();   // the TARGET TYPE's docs
if (xmlText == null || !xmlText.Contains("completionlist"))
    return null;

var documentation = DocumentationComment.FromXmlFragment(xmlText);
var completionListType = documentation.CompletionListCref != null
    ? DocumentationCommentId.GetSymbolsForDeclarationId(documentation.CompletionListCref, compilation)
        .OfType<INamedTypeSymbol>().FirstOrDefault()
    : null;

return completionListType != null && completionListType.IsAccessibleWithin(within)
    ? completionListType
    : null;

Two things follow directly from this code. The provider looks at the documentation of the type that is expected at the caret, never at the symbol you are assigning to. And it reads documentation XML, so anything that stops the docs from being available (no XML file for a referenced DLL, documentation parsing turned off) turns the tag off.

A minimal example

The classic use case is a struct or class with a set of well-known values that you do not want to model as an enum, for example because callers can also construct their own:

// .NET 11, C# 15
namespace Paint;

/// <summary>A color value.</summary>
/// <completionlist cref="Colors"/>
public readonly record struct Color(byte R, byte G, byte B)
{
    public static Color Black { get; } = new(0, 0, 0);
}

public static class Colors
{
    public static Color Red { get; } = new(255, 0, 0);
    public static readonly Color Green = new(0, 255, 0);
    public static string Name => "palette";
    public const int Count = 2;
    public static Color Make() => default;
}

Now type Color c = in Visual Studio. Without the tag, you get the generic completion list. With it, the list opens on the space and offers Colors and its members at the top, the way it would for an enum.

What the completion service actually returns

To pin down the exact behavior rather than describe screenshots, I hosted Roslyn’s completion engine in a console app and asked it for completions at the caret. This is the same CompletionService Visual Studio and the C# extension for VS Code use (the provider derives from LSPCompletionProvider, so it is exposed over the language server too). Setup:

<!-- probe.csproj, built with SDK 11.0.100 -->
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net11.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.CodeAnalysis.CSharp.Features" Version="5.12.0" />
    <PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="5.12.0" />
  </ItemGroup>
</Project>

The core of the probe puts the library code and a one-line “user” file into an AdhocWorkspace and filters the result to the items this post cares about:

// .NET 11, Microsoft.CodeAnalysis.CSharp.Features 5.12.0
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Completion;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Text;

var host = MefHostServices.Create(MefHostServices.DefaultAssemblies);

async Task Run(string lib, string user, CompletionTrigger trigger,
               DocumentationMode mode = DocumentationMode.Parse)
{
    using var ws = new AdhocWorkspace(host);
    var project = ws.AddProject(ProjectInfo.Create(
        ProjectId.CreateNewId(), VersionStamp.Default, "App", "App", LanguageNames.CSharp,
        compilationOptions: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary),
        parseOptions: new CSharpParseOptions(LanguageVersion.Preview, mode),
        metadataReferences: CoreLibReferences()));

    ws.AddDocument(project.Id, "Lib.cs", SourceText.From(lib));
    int caret = user.IndexOf("$$");
    var doc = ws.AddDocument(project.Id, "User.cs", SourceText.From(user.Replace("$$", "")));

    var list = await CompletionService.GetService(doc)!.GetCompletionsAsync(doc, caret, trigger);
    foreach (var item in list.ItemsList.Where(i => i.DisplayText.StartsWith("Color")))
        Console.Write(item.DisplayText + (item.Rules.MatchPriority > 0 ? " [preselect], " : ", "));
    Console.WriteLine();
}

// withTag is the Color/Colors source above as a raw string literal.
// "Color c = $$" with Ctrl+Space, then with a typed space
await Run(withTag, "namespace Paint; class U { void M() { Color c = $$ } }", CompletionTrigger.Invoke);
await Run(withTag, "namespace Paint; class U { void M() { Color c = $$ } }",
          CompletionTrigger.CreateInsertionTrigger(' '));

(CoreLibReferences() returns System.Runtime.dll and System.Private.CoreLib.dll from TRUSTED_PLATFORM_ASSEMBLIES.) Output, trimmed to the relevant items:

== tag, assignment, Ctrl+Space
   Color [preselect], Colors [preselect], Colors.Count, Colors.Green, Colors.Name, Colors.Red
== tag, assignment, typed space
   Color [preselect], Colors [preselect], Colors.Count, Colors.Green, Colors.Name, Colors.Red
== tag, method argument Fill($$), Ctrl+Space
   Color [preselect], Colors [preselect], Colors.Count, Colors.Green, Colors.Name, Colors.Red
== no tag, assignment, Ctrl+Space
   Color [preselect], Color.Black, Colors
== no tag, assignment, typed space
   (completion service returned 0 items)

Read that carefully, because three details are not obvious from the tag’s name.

The members are not filtered by type. Colors.Count is a const int and Colors.Name is a string, and both are offered for a Color slot. The source confirms it: the “same type as the target” check is skipped when the type came from an enum or a completionlist tag. If your static class mixes known values with helpers, the helpers show up too. Keep the cref target a class that contains only the values.

Only static fields and properties count. Colors.Make() is not offered. Methods, nested types, and indexers are skipped.

The tag replaces the default list, it does not add to it. Without the tag, Roslyn already does “enum-like” completion for static members of the target type itself (Color.Black). With the tag, Color.Black disappears and only Colors.* is listed. If you want both sets, move Black into Colors or have Colors.Black forward to it.

The trigger difference also matters in practice. With the tag, the provider answers an insertion trigger of space, (, [, or ~, so the list opens the moment you type Color c = or Fill(. Without it, Roslyn deliberately does not pop up enum-like members on those characters (“to avoid interfering with common typing patterns”, in the source), so you only see Color.Black after Ctrl+Space or after typing a letter.

Variants that work

The same probe covered a few shapes beyond the basic struct:

== nullable Color?, Ctrl+Space
   Color [preselect], Colors [preselect], Colors.Count, Colors.Green, Colors.Name, Colors.Red
== interface IBrush with <completionlist cref="Brushes"/>, Ctrl+Space
   Brushes [preselect], Brushes.Solid, Brushes.Typed, IBrush [preselect], SolidBrush [preselect]
== cref to an enum KnownColor, Ctrl+Space
   Color [preselect], KnownColor [preselect], KnownColor.Red, KnownColor.Green, KnownColor.Blue
  • Nullable<T> is unwrapped, so Color? gets the same list as Color.
  • Interfaces work. This is a good fit for abstractions with a handful of built-in implementations exposed through a static class (Brushes.Solid, Comparers.Ordinal, and so on).
  • The cref can point at an enum. Completion then lists the enum members for a non-enum slot, which only compiles if there is a conversion. Pair it with an implicit operator:
// .NET 11, C# 15
public enum KnownColor { Red, Green, Blue }

/// <completionlist cref="KnownColor"/>
public readonly record struct Color(byte R, byte G, byte B)
{
    public static implicit operator Color(KnownColor k) => k switch
    {
        KnownColor.Red   => new(255, 0, 0),
        KnownColor.Green => new(0, 255, 0),
        _                => new(0, 0, 255),
    };
}

Seven ways the tag silently does nothing

None of these produce a warning, which is why the tag has a reputation for “not working”.

  1. It is on a member, not a type. The question that started this put it on a property. The provider reads type.GetDocumentationCommentXml() of the expected type, so /// <completionlist cref="Colors"/> on public Color Fill { get; set; } changes nothing: k.Fill = still produced Color [preselect], Color.Black, Colors in the probe.
  2. The target is a special type. string, int, object, and the other SpecialType types are skipped up front. You cannot get “known string values” completion for a string parameter this way. The workaround is a small wrapper type (a readonly record struct ContentType(string Value) with an implicit conversion from string) that carries the tag.
  3. The type comes from a DLL shipped without its XML doc file. For a metadata reference, documentation only exists if PackageName.xml sits next to the assembly. In the probe, the same library compiled to an in-memory DLL gave the full Colors.* list when referenced with XmlDocumentationProvider.CreateFromBytes(xml) and fell back to Color.Black without it. If you publish a library, set <GenerateDocumentationFile>true</GenerateDocumentationFile> so the XML file goes into the package.
  4. Documentation parsing is off. With DocumentationMode.None the probe fell back to the default list. In practice this only bites custom tooling: Visual Studio’s project system uses DocumentationMode.Parse when a project does not generate a doc file and Diagnose when it does (ProjectSystemProjectOptionsProcessor.cs), and MSBuildWorkspace forces Parse as well.
  5. The cref does not resolve. With doc generation on, <completionlist cref="Nope"/> gives warning CS1574: XML comment has cref attribute 'Nope' that could not be resolved. With doc generation off there is no warning at all, and the tag just does nothing. Turning on GenerateDocumentationFile (even temporarily) is the quickest way to validate your crefs.
  6. The cref type is not accessible from the code being edited. The provider checks completionListType.IsAccessibleWithin(...), so an internal values class does nothing for consumers in another assembly. Individual members are also filtered by accessibility and by [EditorBrowsable].
  7. The caret is after a dot. Member-access completion (Colors.) is handled by the regular symbol provider. The tag only affects the “what goes in this slot” list.

What the compiler does with it

Nothing beyond cref binding. With GenerateDocumentationFile on, the tag is copied verbatim into the XML file with the cref rewritten to a documentation ID, which is exactly what the provider later resolves with DocumentationCommentId.GetSymbolsForDeclarationId:

<member name="T:Paint.Color">
    <summary>A color value.</summary>
    <completionlist cref="T:Paint.Colors"/>
</member>
<member name="M:Paint.Color.#ctor(System.Byte,System.Byte,System.Byte)">
    <summary>A color value.</summary>
    <completionlist cref="T:Paint.Colors"/>
</member>

The second entry is a C# record detail, not a completionlist one: a positional record’s type-level doc comment is also applied to its primary constructor, so the tag is duplicated there. It is harmless, since the provider only reads the type’s entry.

Because the tag is not in the recommended-tags list, don’t expect documentation generators to render it. Treat it as editor metadata that happens to live in a doc comment.

Should you use it?

Use it when you own a type with a closed or semi-closed set of well-known values that are deliberately not an enum: “smart enum” classes, value objects like Currency or ContentType, or interfaces with built-in implementations. It costs one line, does not affect the compiled IL, and makes the API noticeably more discoverable in Visual Studio and VS Code with the C# extension.

Keep expectations modest. It is undocumented, so there is no compatibility promise, although the provider has been maintained continuously (the last changes to it landed in July 2025). I only verified Roslyn-based editors; JetBrains Rider uses its own completion engine and was not tested. And it cannot help the most-requested case, completion for plain string parameters, without the wrapper type from gotcha 2.

Sources

Comments

Sign in with GitHub to comment. Reactions and replies thread back to the comments repo.