{"record":{"id":"9867e68776f2a3b8","repo":"stride3d/stride","slug":"the-given-type-does-not-match-the-given-object","errorCode":null,"errorMessage":"The given type does not match the given object.","messagePattern":"The given type does not match the given object\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/presentation/Stride.Core.Quantum/References/ObjectReference.cs","lineNumber":25,"sourceCode":"/// A class representing a reference to another object that has a different model.\n/// </summary>\npublic sealed class ObjectReference : IReferenceInternal\n{\n    private readonly Type type;\n    private object? orphanObject;\n\n    /// <summary>\n    /// Initialize a new instance of the <see cref=\"ObjectReference\"/> class using a data object.\n    /// </summary>\n    /// <remarks>This constructor should be used when the given <see cref=\"objectValue\"/> has no mode node yet existing.</remarks>\n    /// <param name=\"objectValue\">A data object to reference. Can be null.</param>\n    /// <param name=\"objectType\">The type of data object to reference.</param>\n    /// <param name=\"index\">The index of this reference in its parent reference, if it is a <see cref=\"ReferenceEnumerable\"/>.</param>\n    internal ObjectReference(object? objectValue, Type objectType, NodeIndex index)\n    {\n        Reference.CheckReferenceCreationSafeGuard();\n        ArgumentNullException.ThrowIfNull(objectType);\n        if (objectValue != null && !objectType.IsInstanceOfType(objectValue)) throw new ArgumentException(\"The given type does not match the given object.\", nameof(objectValue));\n        orphanObject = objectValue;\n        type = objectType;\n        Index = index;\n    }\n\n    /// <summary>\n    /// Gets the model node targeted by this reference, if available.\n    /// </summary>\n    public IObjectNode? TargetNode { get; private set; }\n\n    /// <inheritdoc/>\n    public object? ObjectValue => TargetNode?.Retrieve() ?? orphanObject;\n\n    /// <summary>\n    /// 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\"/>.\n    /// </summary>\n    public NodeIndex Index { get; }\n","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/presentation/Stride.Core.Quantum/References/ObjectReference.cs#L7-L43","documentation":"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.","triggerScenarios":"Thrown at sources/presentation/Stride.Core.Quantum/References/ObjectReference.cs:25 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}