{"record":{"id":"fea4eb31cdccf3e7","repo":"tui-cs/Terminal.Gui","slug":"unable-to-create-string-from-color-with-value-arg","errorCode":null,"errorMessage":"Unable to create string from Color with value {Argb}, using format string {formatString}","messagePattern":"Unable to create string from Color with value (.+?), using format string (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"info","filePath":"Terminal.Gui/Drawing/Color/Color.Formatting.cs","lineNumber":137,"sourceCode":"            // G format string and null formatProvider - Output as 32-bit hex according to invariant culture rules from Argb\n            ( ['G'], null) => $\"#{A:X2}{R:X2}{G:X2}{B:X2}\",\n\n            // d format string and null formatProvider - Output as 24-bit decimal rgb(r,g,b) according to invariant culture rules from R, G, and B\n            ( ['d'], null) => $\"rgb({R:D},{G:D},{B:D})\",\n\n            // D format string and null formatProvider - Output as 32-bit decimal rgba(r,g,b,a) according to invariant culture rules from R, G, B, and A. Non-standard: a is a decimal byte value.\n            ( ['D'], null) => $\"rgba({R:D},{G:D},{B:D},{A:D})\",\n\n            // All other cases (formatString is not null here) - Delegate to formatProvider, first, and otherwise to invariant culture, and try to format the provided string from the channels\n            ({ }, _) => string.Format (\n                                       formatProvider ?? CultureInfo.InvariantCulture,\n                                       CompositeFormat.Parse (formatString),\n                                       R,\n                                       G,\n                                       B,\n                                       A\n                                      ),\n            _ => throw new InvalidOperationException (\n                                                      $\"Unable to create string from Color with value {Argb}, using format string {formatString}\"\n                                                     )\n        }\n               ?? throw new InvalidOperationException (\n                                                       $\"Unable to create string from Color with value {Argb}, using format string {formatString}\"\n                                                      );\n    }\n\n    /// <inheritdoc/>\n    /// <remarks>\n    ///     <para>\n    ///         This method should be used only when absolutely necessary, because it <b>always</b> has more overhead than\n    ///         <see cref=\"ToString(string?,System.IFormatProvider?)\"/>, as this method results in an intermediate allocation\n    ///         of one or more instances of <see langword=\"string\"/> and a copy of that string to\n    ///         <paramref name=\"destination\"/> if formatting was successful. <br/> When possible, use\n    ///         <see cref=\"ToString(string?,System.IFormatProvider?)\"/>, which attempts to avoid intermediate allocations.\n    ///     </para>\n    ///     <para>","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/Drawing/Color/Color.Formatting.cs#L119-L155","documentation":"Defensive throw on the discarded '_' arm of the pattern switch in Color.ToString(string?, IFormatProvider?). The switch exhaustively covers all (formatString, formatProvider) combinations: null/empty format with any provider, and any non-null format with any provider. This '_' arm is therefore effectively unreachable in normal C# evaluation; it exists as a compile-time-completeness safeguard. If ever hit, it indicates the runtime produced a (formatString, provider) pair the author believed impossible.","triggerScenarios":"Effectively unreachable. The only theoretical way is a future refactor that adds a new branch returning before this arm, or a JIT/trimming bug corrupting pattern matching. The message reports the Color's Argb value and the formatString for diagnostics.","commonSituations":"Not expected in practice; if you see it, suspect a corrupted build, a patched Color.Formatting.cs, or a runtime ABI mismatch.","solutions":["Treat this as a bug report: capture the Argb value and formatString from the message and file an issue against Terminal.Gui.","Rebuild from a clean checkout to rule out a stale/partially-compiled Color.Formatting.cs.","Avoid passing exotic formatString/provider combinations; use the documented single-letter formats ('g','G','d','D')."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { string s = color.ToString (fmt, provider); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains (\"Unable to create string from Color\"))\n{ /* report as Terminal.Gui internal bug; fall back to color.ToString() */ }","preventionTips":["Use the documented single-letter formats ('g','G','d','D') or null.","If you see this, suspect a corrupted build; rebuild from clean source.","File an issue with the Argb and formatString values from the message."],"tags":["drawing","color","formatting","unreachable","defensive"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}