spectreconsole/spectre.console · error · InvalidOperationException

Profile enricher of type '{enricher.GetType().FullName}' doe

Error message

Profile enricher of type '{enricher.GetType().FullName}' does not have a name.

What it means

Thrown by ProfileEnricher.Enrich when an IProfileEnricher in the configured set has a Name that is null, empty, or whitespace. Names are used to record which enrichers applied to a profile (profile.AddEnricher), so an unnamed enricher is invalid. This guards both built-in and user-supplied enrichers.

Source

Thrown at src/Spectre.Console/Enrichment/ProfileEnricher.cs:37

        new TfsEnricher(),
        new TravisEnricher()
    ];

    public static void Enrich(
        Profile profile,
        ProfileEnrichment settings,
        IDictionary<string, string>? environmentVariables)
    {
        ArgumentNullException.ThrowIfNull(profile);

        settings ??= new ProfileEnrichment();

        var variables = GetEnvironmentVariables(environmentVariables);
        foreach (var enricher in GetEnrichers(settings))
        {
            if (string.IsNullOrWhiteSpace(enricher.Name))
            {
                throw new InvalidOperationException($"Profile enricher of type '{enricher.GetType().FullName}' does not have a name.");
            }

            if (enricher.Enabled(variables))
            {
                enricher.Enrich(profile);
                profile.AddEnricher(enricher.Name);
            }
        }
    }

    private static List<IProfileEnricher> GetEnrichers(ProfileEnrichment settings)
    {
        var enrichers = new List<IProfileEnricher>();

        if (settings.UseDefaultEnrichers)
        {
            enrichers.AddRange(_defaultEnrichers);
        }

View on GitHub (pinned to 0acc92fada)

Solutions

  1. Give your custom IProfileEnricher a stable non-empty Name property
  2. If you do not need a custom enricher, remove it from settings.Enrichment
  3. Audit third-party enrichers for a non-empty Name before registration

Example fix

// before
public sealed class MyEnricher : IProfileEnricher
{
    public string Name => ""; // throws
    public void Enrich(Profile p) { }
}

// after
public sealed class MyEnricher : IProfileEnricher
{
    public string Name => "my-enricher";
    public void Enrich(Profile p) { }
}
Defensive patterns

Strategy: validation

Validate before calling

// Validate a custom enricher's Name before registration
foreach (var e in myEnrichers)
{
    if (string.IsNullOrWhiteSpace(e.Name))
        throw new InvalidOperationException($"Enricher {e.GetType().FullName} has no name");
}

Type guard

static bool HasValidName(IProfileEnricher e) => !string.IsNullOrWhiteSpace(e.Name);

Try / catch

try
{
    // creation triggers ProfileEnricher.Enrich
    var console = AnsiConsole.Create(settings);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("does not have a name"))
{
    // a registered enricher returned an empty Name
}

Prevention

When it happens

Trigger: Registering a custom IProfileEnricher whose Name property returns null/""/whitespace, and including it in the ProfileEnrichment set used at console creation.

Common situations: Third-party or hand-written enricher that forgot to implement Name; an enricher whose Name is computed from missing config; copy of a built-in enricher with the name overridden to empty.

Related errors


AI-assisted analysis of spectreconsole/spectre.console@0acc92fada (2026-08-13). Data as JSON: /api/errors/301bbe2c9c7b6fd5. Report an issue: GitHub.