stride3d/stride · error · InvalidOperationException
Can not convert value to the required type
Error message
Can not convert value to the required type
What it means
GraphNodeBase.ConvertValue throws InvalidOperationException when TypeConverterHelper cannot convert the supplied value to the required target type. It is the safe coercion point used when setting node values, guarding against storing incompatible values in the graph.
Solutions
- Pre-convert the value yourself (Convert.ChangeType, int.Parse, etc.) before assigning
- Register a custom TypeConverter in TypeConverterHelper for the source/target pair
- Assign values whose runtime type matches the member's declared type
- Catch InvalidOperationException on assignment and report a user-facing type error
Example fix
// before
node.SetData("42"); // int member, no converter
// after
if (int.TryParse(s, out var v)) node.SetData(v); Defensive patterns
Strategy: validation
Validate before calling
if (value != null && !TypeConverterHelper.TryConvert(value, targetType, out _)) throw new InvalidOperationException($"Cannot convert {value.GetType()} to {targetType}"); Type guard
bool CanAssign<TTarget>(object? v) => v is null || v is TTarget || TypeConverterHelper.TryConvert(v, typeof(TTarget), out _);
Try / catch
try { node.Update(newValue); } catch (InvalidOperationException ex) when (ex.Message.Contains("convert")) { // surface a type error to the user } Prevention
- Match value runtime types to member declared types
- Register custom TypeConverters for domain conversions
- Parse strings into typed values before assignment
When it happens
Trigger: Assigning a value to a node or member (INode.SetData/Update) whose runtime type has no registered TypeConverter to the member's declared type, e.g. setting string "42" on an int member when no converter applies, or assigning incompatible object types.
Common situations: Data-binding values from UI (strings) into typed model members; deserializing JSON where numbers arrived as strings; type changes between library versions that removed a converter.
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
- objectValue type does not match objectType
- Two bundles with name
- Could not find dependency
- content reference(s) were not rooted (see errors above)…
- Could not find asset
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/0aa757438e8b9d71.
Report an issue: GitHub.
Appendix: source
Thrown at sources/presentation/Stride.Core.Quantum/GraphNodeBase.cs:88
}
return null;
}
/// <summary>
/// Seal the node, indicating its construction is finished and that no more children or commands will be added.
/// </summary>
public void Seal()
{
IsSealed = true;
}
protected static object? ConvertValue(object? value, Type type)
{
if (value == null)
return null;
if (!TypeConverterHelper.TryConvert(value, type, out var convertedValue))
throw new InvalidOperationException("Can not convert value to the required type");
return convertedValue;
}
}
View on GitHub (pinned to 96fad776d2)