{"record":{"id":"def5614b9a6a2f6a","repo":"SixLabors/ImageSharp","slug":"invalid-calculation-type","errorCode":null,"errorMessage":"Invalid calculation type","messagePattern":"Invalid calculation type","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/ColorProfiles/Icc/Calculators/CurveCalculator.cs","lineNumber":45,"sourceCode":"                this.gamma = 1f / this.gamma;\n            }\n\n            this.type = CalculationType.Gamma;\n        }\n        else\n        {\n            this.lutCalculator = new LutCalculator(entry.CurveData, inverted);\n            this.type = CalculationType.Lut;\n        }\n    }\n\n    public float Calculate(float value)\n        => this.type switch\n        {\n            CalculationType.Identity => value,\n            CalculationType.Gamma => MathF.Pow(value, this.gamma), // TODO: This could be optimized using a LUT. See SrgbCompanding\n            CalculationType.Lut => this.lutCalculator.Calculate(value),\n            _ => throw new InvalidOperationException(\"Invalid calculation type\"),\n        };\n}\n","sourceCodeStart":27,"sourceCodeEnd":48,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/ColorProfiles/Icc/Calculators/CurveCalculator.cs#L27-L48","documentation":"CurveCalculator.Calculate uses a switch over its CalculationType (Identity, Gamma, Lut) and throws InvalidOperationException for any other value. Since the type is set only by the calculator's own constructor from known tag entries, reaching the default arm signals corrupted internal state — the calculator was built without a recognized curve type.","triggerScenarios":"Calling Calculate on a CurveCalculator that was constructed in a way that left type as an undefined CalculationType value (default-initialized struct/enum or internal construction bug).","commonSituations":"Rare; usually indicates a library-internal invariant violation, memory corruption of the calculator, or constructing the calculator manually with a default(CalculationType) that isn't a valid member.","solutions":["Reconstruct the CurveCalculator from a valid IccCurveTagDataEntry via the public constructor.","Check whether a custom/direct construction path assigned an out-of-range CalculationType and fix it.","If triggered by normal library use, report it as a bug with the offending ICC profile."],"exampleFix":"// before\nvar calc = new CurveCalculator(); // default state, invalid type\n// after\nvar calc = new CurveCalculator(curveTagDataEntry, inverted: false);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { float v = curveCalculator.Calculate(x); }\ncatch (InvalidOperationException ex) when (ex.Message == \"Invalid calculation type\") { /* rebuild calculator from a valid curve tag entry */ }","preventionTips":["Construct CurveCalculator only through the public constructor from IccCurveTagDataEntry.","Never assign CalculationType fields directly or rely on default enum values.","If this fires from normal library use, file a bug with the offending profile."],"tags":["icc","color-management","invalid-enum-value","csharp"],"backgroundTag":"invalid-enum-value","analyzedSha":"59ce6af6fc29027cda277ef62d4d1694a8acce91","analyzedAt":"2026-09-13T18:34:59.331Z","contentChangedAt":"2026-09-13T18:34:59.331Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}