stride3d/stride · error · ArgumentException
objectValue type does not match objectType
Error message
objectValue type does not match objectType
What it means
Reference.CreateReference is the single factory for building IReference instances in Stride.Core.Quantum. Before creating the reference it validates that the runtime object actually is an instance of the declared node type; if objectValue is non-null and not assignable to objectType, the graph would hold a reference whose content does not match its declared type, so it throws ArgumentException immediately.
Solutions
- Verify the objectValue you pass is an instance of objectType before calling (objectValue is null or objectType.IsInstanceOfType(objectValue)).
- Make sure the Type comes from the same reflection source (descriptor/member) as the value — prefer nodeContainer/factory helpers over hand-built references.
- If you truly have a mismatch, use the correct declared type for the value, or cast/convert the value to the declared type first.
- Note the method is marked Obsolete ('will be rewritten to handle separately the different types of references') — migrate to the current reference-creation API in your Stride version.
Example fix
// before var reference = Reference.CreateReference(order, typeof(Customer), nodeIndex, false); // after var reference = Reference.CreateReference(order, order.GetType(), nodeIndex, false);
Defensive patterns
Strategy: validation
Validate before calling
if (objectValue is null || objectType.IsInstanceOfType(objectValue))
var reference = Reference.CreateReference(objectValue, objectType, nodeIndex, isMember); Type guard
bool IsCompatible(object? value, Type declaredType) => value is null || declaredType.IsInstanceOfType(value);
Try / catch
try { var r = Reference.CreateReference(value, type, index, isMember); }
catch (ArgumentException ex) when (ex.ParamName == "objectValue") { /* fix declared type or value source */ } Prevention
- Derive both value and Type from the same reflection descriptor/member
- Prefer container/factory APIs over hand-constructing references
- Avoid the Obsolete CreateReference; use the current Stride reference-creation API
When it happens
Trigger: Calling Reference.CreateReference(objectValue, objectType, index, isMember) with a non-null objectValue whose concrete type is not assignable to objectType — e.g. CreateReference("someString", typeof(int), index, false) or passing a derived object where an unrelated base was declared.
Common situations: Custom NodeFactory/NodeBuilder code that mismatches reflection metadata with actual values; generic code that passes Type objects captured from a different member; refactoring a property's type without updating the code that declares the node type; obsolete-API usage paths that construct references by hand.
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
- Type [ ] must be assignable to Asset
- Can not convert value to the required type
- A NodeIndex instance cannot be passed as the value of…
- The object is not an IEnumerable
- Two bundles with name
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/18f08eecf5f1f12f.
Report an issue: GitHub.
Appendix: source
Thrown at sources/presentation/Stride.Core.Quantum/References/Reference.cs:16
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
using System.Collections;
using Stride.Core.Reflection;
namespace Stride.Core.Quantum.References;
internal static class Reference
{
private static readonly ThreadLocal<int> CreatingReference = new();
[Obsolete("This method will be rewritten to handle separately the different types of references")]
internal static IReference? CreateReference(object? objectValue, Type objectType, NodeIndex index, bool isMember)
{
if (objectValue != null && !objectType.IsInstanceOfType(objectValue)) throw new ArgumentException(@"objectValue type does not match objectType", nameof(objectValue));
if (!CreatingReference.IsValueCreated)
CreatingReference.Value = 0;
++CreatingReference.Value;
IReference? reference;
var isCollection = HasCollectionReference(objectValue?.GetType() ?? objectType);
if (isMember)
{
reference = new ObjectReference(objectValue, objectType, index);
}
else
{
if (objectValue != null && isCollection && index.IsEmpty)
{
reference = new ReferenceEnumerable((IEnumerable)objectValue, objectType);
}View on GitHub (pinned to 96fad776d2)