{"record":{"id":"cd0522d826171f6c","repo":"spectreconsole/spectre.console","slug":"failed-to-read-colors-json-at-file-path","errorCode":null,"errorMessage":"Failed to read colors.json at {file.Path}","messagePattern":"Failed to read colors\\.json at (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Spectre.Console.SourceGenerator/Colors/ColorGenerator.cs","lineNumber":28,"sourceCode":"/// </summary>\n[Generator]\npublic class ColorGenerator : IIncrementalGenerator\n{\n    // UTF-8 without a BOM, matching the repository's source file convention\n    // and keeping the checked-in generated files deterministic.\n    private static readonly Encoding Utf8NoBom = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false);\n\n    /// <inheritdoc />\n    public void Initialize(IncrementalGeneratorInitializationContext context)\n    {\n        // Find colors.json and parse it in the pipeline (for caching)\n        // Step 1: Extract text (cached by string value equality)\n        // Step 2: Parse to models (cached by EquatableArray value equality)\n        var colors = context.AdditionalTextsProvider\n            .Where(static file => file.Path.EndsWith(\"colors.json\", StringComparison.OrdinalIgnoreCase))\n            .Select(static (file, ct) =>\n                file.GetText(ct)?.ToString()\n                ?? throw new InvalidOperationException($\"Failed to read colors.json at {file.Path}\"))\n            .Select(static (text, _) => ColorParser.ParseAll(text))\n            .Collect();\n\n        // Register source output - only emit, no parsing (parsing is cached above)\n        context.RegisterSourceOutput(colors, static (spc, models) =>\n        {\n            if (models.IsEmpty)\n            {\n                return;\n            }\n\n            if (models.Length > 1)\n            {\n                spc.ReportDiagnostic(Diagnostic.Create(\n                    new DiagnosticDescriptor(\n                        \"SPECINTERNALCOL001\",\n                        \"Multiple colors.json files found\",\n                        \"Multiple colors.json files were found. Only the first one will be used.\",","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/spectreconsole/spectre.console/blob/0acc92fada6c42f13984e79c2b5f3d993bdfb099/src/Spectre.Console.SourceGenerator/Colors/ColorGenerator.cs#L10-L46","documentation":"Thrown inside the colors.json Roslyn incremental source generator when an AdditionalFiles entry ending in colors.json was matched but AdditionalText.GetText returned null, i.e. the file was itemized by MSBuild but its contents could not be read at generation time. It is an InvalidOperationException raised inside the generator pipeline, so it surfaces as a compile-time build error.","triggerScenarios":"The colors.json AdditionalFiles item exists in the project graph but Roslyn cannot retrieve its text (locked, deleted between itemization and generation, unreadable, or empty/garbled).","commonSituations":"Corrupted or hand-edited Spectre.Console source-generator data file; antivirus/IDE file lock; partial git checkout; restoring a package whose colors.json is missing or zero-byte; a broken AdditionalFiles path glob.","solutions":["Run a clean rebuild (dotnet clean && dotnet build) to re-read the AdditionalFiles","Verify the colors.json referenced by the Spectre.Console source generator exists on disk and is readable","Reinstall/restore the Spectre.Console package so its bundled colors.json is refreshed","Check for file locks from antivirus or another IDE process holding colors.json"],"exampleFix":"# before: stale/locked AdditionalFiles causes generation failure\n# after: force a clean generation\ndotnet clean\ndotnet restore\ndotnet build","handlingStrategy":"validation","validationCode":"// Pre-build check: confirm the colors.json AdditionalFiles item resolves\ndotnet msbuild -getItem:AdditionalFiles | findstr colors.json","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep the shipped colors.json intact; do not hand-edit generator data","Add a CI step that fails if any Spectre.Console data file is zero-byte or missing","Close IDEs/antivirus that may lock AdditionalFiles during build"],"tags":["source-generator","build","json","roslyn","colors"],"backgroundTag":null,"analyzedSha":"0acc92fada6c42f13984e79c2b5f3d993bdfb099","analyzedAt":"2026-08-13T18:27:21.983Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}