{"record":{"id":"304237ff378ce2e0","repo":"stride3d/stride","slug":"the-lightcomponent-doesn-t-contain-a-color-light-type","errorCode":null,"errorMessage":"The LightComponent doesn't contain a color light type IColorLight","messagePattern":"The LightComponent doesn't contain a color light type IColorLight","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Engine/Engine/LightComponentExtensions.cs","lineNumber":31,"sourceCode":"    /// Extensions for the <see cref=\"LightComponent\"/> class.\n    /// </summary>\n    public static class LightComponentExtensions\n    {\n        /// <summary>\n        /// Gets the color from a <see cref=\"LightComponent\"/> assuming that the <see cref=\"LightComponent.Type\"/> is an instance of <see cref=\"IColorLight\"/> \n        /// </summary>\n        /// <param name=\"light\">The light component.</param>\n        /// <returns>The color of the light component</returns>\n        /// <exception cref=\"InvalidOperationException\">If the LightComponent doesn't contain a color light type IColorLight</exception>\n        public static Color3 GetColor(this LightComponent light)\n        {\n            var colorLight = light.Type as IColorLight;\n            var lightColorRgb = colorLight?.Color as ColorRgbProvider;\n            if (lightColorRgb != null)\n            {\n                return lightColorRgb.Value;\n            }\n            throw new InvalidOperationException(\"The LightComponent doesn't contain a color light type IColorLight\");\n        }\n\n        /// <summary>\n        /// Sets the color from a <see cref=\"LightComponent\"/> assuming that the <see cref=\"LightComponent.Type\"/> is an instance of <see cref=\"IColorLight\"/> \n        /// </summary>\n        /// <param name=\"light\">The light component.</param>\n        /// <param name=\"color\">The light color.</param>\n        /// <exception cref=\"InvalidOperationException\">If the LightComponent doesn't contain a color light type IColorLight</exception>\n        public static void SetColor(this LightComponent light, Color3 color)\n        {\n            var colorLight = light.Type as IColorLight;\n            if (colorLight == null)\n                throw new InvalidOperationException(\"The LightComponent doesn't contain a color light type IColorLight\");\n\n            var lightColorRgb = colorLight.Color as ColorRgbProvider ?? new ColorRgbProvider();\n            lightColorRgb.Value = color;\n            colorLight.Color = lightColorRgb;\n        }","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Engine/Engine/LightComponentExtensions.cs#L13-L49","documentation":"LightComponentExtensions.GetColor casts light.Type to IColorLight and expects its Color to be a ColorRgbProvider; if the light type is not a color light (or the color provider is a different kind), it throws InvalidOperationException. The extension only supports RGB color lights.","triggerScenarios":"Calling light.GetColor() when LightComponent.Type is not IColorLight (e.g. directional/sun, ambient) or when the IColorLight's Color is not a ColorRgbProvider.","commonSituations":"Iterating all lights in a scene and calling GetColor on every LightComponent regardless of its light type; lights created from templates with non-RGB color providers.","solutions":["Check light.Type is IColorLight and its Color is ColorRgbProvider before calling GetColor.","Restrict GetColor calls to lights whose Type is a color light (e.g. LightDirectionalColor, LightPointColor).","Handle non-color lights explicitly with a fallback instead of calling the extension."],"exampleFix":"// before\nvar color = anyLight.GetColor(); // throws for non-color lights\n// after\nif (anyLight.Type is IColorLight)\n{\n    var color = anyLight.GetColor();\n}","handlingStrategy":"type-guard","validationCode":"if (light?.Type is IColorLight) { var c = light.GetColor(); }","typeGuard":"bool IsColorLight(LightComponent l) => l?.Type is IColorLight;","tryCatchPattern":"try { color = light.GetColor(); }\ncatch (InvalidOperationException) { color = Color3.White; /* non-color light */ }","preventionTips":["Filter scene lights to IColorLight types before color operations.","Keep an explicit allow-list of light types you mutate color on."],"tags":["lights","invalid-operation","extension-methods","type-cast"],"backgroundTag":"type-mismatch","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}