spectreconsole/spectre.console · error · InvalidOperationException

Failed to read emoji.json at {file.Path}

Error message

Failed to read emoji.json at {file.Path}

What it means

Thrown inside the emoji.json Roslyn incremental source generator when an AdditionalFiles entry ending in emoji.json matched but GetText returned null. Same shape as the colors.json read failure but for the emoji data file; it surfaces as a compile-time InvalidOperationException in the generator pipeline.

Source

Thrown at src/Spectre.Console.SourceGenerator/Emojis/EmojiGenerator.cs:28

/// </summary>
[Generator]
public class EmojiGenerator : IIncrementalGenerator
{
    // UTF-8 without a BOM, matching the repository's source file convention
    // and keeping the checked-in generated files deterministic.
    private static readonly Encoding Utf8NoBom = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false);

    /// <inheritdoc />
    public void Initialize(IncrementalGeneratorInitializationContext context)
    {
        // Find emoji.json and parse it in the pipeline (for caching)
        // Step 1: Extract text (cached by string value equality)
        // Step 2: Parse to models (cached by EquatableArray value equality)
        var emojis = context.AdditionalTextsProvider
            .Where(static file => file.Path.EndsWith("emoji.json", StringComparison.OrdinalIgnoreCase))
            .Select(static (file, ct) =>
                file.GetText(ct)?.ToString()
                ?? throw new InvalidOperationException($"Failed to read emoji.json at {file.Path}"))
            .Select(static (text, _) => EmojiParser.ParseAll(text))
            .Collect();

        // Register implementation source output - we do not use these emojis directly in the source
        // and this will allow IDEs to optionally skip running this generator for intellisense and the such, but it will
        // always run when compiling.
        // see https://github.com/dotnet/roslyn/blob/main/docs/features/incremental-generators.md#outputting-values
        context.RegisterImplementationSourceOutput(emojis, static (spc, models) =>
        {
            if (models.IsEmpty)
            {
                return;
            }

            if (models.Length > 1)
            {
                spc.ReportDiagnostic(Diagnostic.Create(
                    new DiagnosticDescriptor(

View on GitHub (pinned to 0acc92fada)

Solutions

  1. Clean rebuild (dotnet clean && dotnet build) to re-read AdditionalFiles
  2. Confirm the emoji.json used by the generator exists and is readable on disk
  3. Restore/reinstall the Spectre.Console package to refresh emoji.json
  4. Release any process lock (other IDE, antivirus) on emoji.json

Example fix

# before: emoji.json unreadable during generation
# after: clean generation
dotnet clean
dotnet restore
dotnet build
Defensive patterns

Strategy: validation

Validate before calling

// Pre-build check: confirm emoji.json AdditionalFiles item resolves
dotnet msbuild -getItem:AdditionalFiles | findstr emoji.json

Prevention

When it happens

Trigger: The emoji.json AdditionalFiles item is in the project graph but its text cannot be read at generation time (locked, deleted mid-build, unreadable, or empty).

Common situations: Corrupted emoji.json; antivirus file lock; partial checkout; package restore that left emoji.json missing or zero-byte; a broken AdditionalFiles include.

Related errors


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