stride3d/stride · error · InvalidOperationException
The LightComponent doesn't contain a color light type…
Error message
The LightComponent doesn't contain a color light type IColorLight
What it means
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.
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.
Example fix
// before
var color = anyLight.GetColor(); // throws for non-color lights
// after
if (anyLight.Type is IColorLight)
{
var color = anyLight.GetColor();
} Defensive patterns
Strategy: type-guard
Validate before calling
if (light?.Type is IColorLight) { var c = light.GetColor(); } Type guard
bool IsColorLight(LightComponent l) => l?.Type is IColorLight;
Try / catch
try { color = light.GetColor(); }
catch (InvalidOperationException) { color = Color3.White; /* non-color light */ } Prevention
- Filter scene lights to IColorLight types before color operations.
- Keep an explicit allow-list of light types you mutate color on.
When it happens
Trigger: Calling light.GetColor() when LightComponent.Type is not IColorLight (e.g. directional/sun, ambient) or when the IColorLight's Color is not a ColorRgbProvider.
Common situations: 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.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- A dependency object must be attached in order to register a…
- A dependency object must be attached in order to unregister…
- A serializer factory selector must be sealed before being…
- ApplicationDataSubDirectory cannot be modified after the…
- Can only merge simple MeshDrawData.
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/304237ff378ce2e0.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Engine/Engine/LightComponentExtensions.cs:31
/// Extensions for the <see cref="LightComponent"/> class.
/// </summary>
public static class LightComponentExtensions
{
/// <summary>
/// Gets the color from a <see cref="LightComponent"/> assuming that the <see cref="LightComponent.Type"/> is an instance of <see cref="IColorLight"/>
/// </summary>
/// <param name="light">The light component.</param>
/// <returns>The color of the light component</returns>
/// <exception cref="InvalidOperationException">If the LightComponent doesn't contain a color light type IColorLight</exception>
public static Color3 GetColor(this LightComponent light)
{
var colorLight = light.Type as IColorLight;
var lightColorRgb = colorLight?.Color as ColorRgbProvider;
if (lightColorRgb != null)
{
return lightColorRgb.Value;
}
throw new InvalidOperationException("The LightComponent doesn't contain a color light type IColorLight");
}
/// <summary>
/// Sets the color from a <see cref="LightComponent"/> assuming that the <see cref="LightComponent.Type"/> is an instance of <see cref="IColorLight"/>
/// </summary>
/// <param name="light">The light component.</param>
/// <param name="color">The light color.</param>
/// <exception cref="InvalidOperationException">If the LightComponent doesn't contain a color light type IColorLight</exception>
public static void SetColor(this LightComponent light, Color3 color)
{
var colorLight = light.Type as IColorLight;
if (colorLight == null)
throw new InvalidOperationException("The LightComponent doesn't contain a color light type IColorLight");
var lightColorRgb = colorLight.Color as ColorRgbProvider ?? new ColorRgbProvider();
lightColorRgb.Value = color;
colorLight.Color = lightColorRgb;
}View on GitHub (pinned to 96fad776d2)