stride3d/stride · error · ArgumentException
The given type does not match the given object.
Error message
The given type does not match the given object.
What it means
A validation guard in the ObjectReference constructor: the declared reference type does not match the runtime type of the supplied objectValue. An ObjectReference pairs a static type with a data object; when the object is not an instance of that type, later graph operations (node creation, content retrieval) would type-check incorrectly, so the mismatch is rejected at construction time.
Solutions
- Pass an objectValue whose runtime type matches (or is assignable to) the type argument of the ObjectReference constructor.
- When unsure of the concrete type, pass objectValue.GetType() as the type parameter instead of a hard-coded or stale type.
- At the call site, check type.IsInstanceOfType(objectValue) before constructing the reference and fix the mismatched pairing.
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at sources/presentation/Stride.Core.Quantum/References/ObjectReference.cs:25 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/9867e68776f2a3b8.
Report an issue: GitHub.
Appendix: source
Thrown at sources/presentation/Stride.Core.Quantum/References/ObjectReference.cs:25
/// A class representing a reference to another object that has a different model.
/// </summary>
public sealed class ObjectReference : IReferenceInternal
{
private readonly Type type;
private object? orphanObject;
/// <summary>
/// Initialize a new instance of the <see cref="ObjectReference"/> class using a data object.
/// </summary>
/// <remarks>This constructor should be used when the given <see cref="objectValue"/> has no mode node yet existing.</remarks>
/// <param name="objectValue">A data object to reference. Can be null.</param>
/// <param name="objectType">The type of data object to reference.</param>
/// <param name="index">The index of this reference in its parent reference, if it is a <see cref="ReferenceEnumerable"/>.</param>
internal ObjectReference(object? objectValue, Type objectType, NodeIndex index)
{
Reference.CheckReferenceCreationSafeGuard();
ArgumentNullException.ThrowIfNull(objectType);
if (objectValue != null && !objectType.IsInstanceOfType(objectValue)) throw new ArgumentException("The given type does not match the given object.", nameof(objectValue));
orphanObject = objectValue;
type = objectType;
Index = index;
}
/// <summary>
/// Gets the model node targeted by this reference, if available.
/// </summary>
public IObjectNode? TargetNode { get; private set; }
/// <inheritdoc/>
public object? ObjectValue => TargetNode?.Retrieve() ?? orphanObject;
/// <summary>
/// Gets the index of this reference in its parent collection. If the reference is not in a collection, this will return <see cref="Quantum.NodeIndex.Empty"/>.
/// </summary>
public NodeIndex Index { get; }
View on GitHub (pinned to 96fad776d2)