{"record":{"id":"6fbb237ef970178a","repo":"stride3d/stride","slug":"a-collection-type","errorCode":null,"errorMessage":"A collection type","messagePattern":"A collection type","errorType":"exception","errorClass":"QuantumConsistencyException","httpStatus":null,"severity":"error","filePath":"sources/presentation/Stride.Core.Quantum/DefaultNodeBuilder.cs","lineNumber":70,"sourceCode":"        return rootNode!;\n    }\n\n    /// <inheritdoc/>\n    public override void VisitObject(object obj, ObjectDescriptor descriptor, bool visitMembers)\n    {\n        ITypeDescriptor currentDescriptor = descriptor;\n\n        bool isRootNode = contextStack.Count == 0;\n        if (isRootNode)\n        {\n            // If we're visiting a value type as \"object\" we need to use a special \"boxed\" node.\n            var content = descriptor.Type.IsValueType ? NodeFactory.CreateBoxedNode(this, rootGuid, obj, descriptor)\n                : NodeFactory.CreateObjectNode(this, rootGuid, obj, descriptor);\n\n            currentDescriptor = content.Descriptor;\n            rootNode = (IInitializingObjectNode)content;\n            if (content.IsReference && currentDescriptor.Type.IsStruct())\n                throw new QuantumConsistencyException(\"A collection type\", \"A structure type\", rootNode);\n\n            PushContextNode(rootNode);\n        }\n\n        if (!PrimitiveTypeFilter.IsPrimitiveType(currentDescriptor.Type))\n        {\n            base.VisitObject(obj, descriptor, true);\n        }\n\n        if (isRootNode)\n        {\n            PopContextNode();\n            rootNode!.Seal();\n        }\n    }\n\n    /// <inheritdoc/>\n    public override void VisitCollection(IEnumerable collection, CollectionDescriptor descriptor)","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/presentation/Stride.Core.Quantum/DefaultNodeBuilder.cs#L52-L88","documentation":"DefaultNodeBuilder.VisitObject throws QuantumConsistencyException when a node created from an object turns out to be a reference node while its descriptor type is a struct. Quantum expects struct-typed values to be boxed/plain value nodes, not reference nodes, so this signals an internal node-factory/type-descriptor inconsistency.","triggerScenarios":"Visiting an object whose TypeDescriptor reports IsValueType (struct) but NodeFactory.CreateBoxedNode/CreateObjectNode produces a node with IsReference=true, e.g. a type whose descriptor is inconsistent (custom ITypeDescriptor, mismatched metadata) during Build of a NodeContainer.","commonSituations":"Custom type descriptors or node factories overriding default behavior; struct types registered or resolved through descriptors that mark them as reference types; library version mismatch where IsReference detection changed.","solutions":["Inspect the struct type whose descriptor sets IsReference and fix the custom descriptor/factory so structs are not treated as references","Update Stride.Core packages so Quantum and TypeDescriptor versions match","If the type should be a class, change the model so the descriptor's type is not a struct","Catch QuantumConsistencyException during Build and log the offending type to identify the misregistered descriptor"],"exampleFix":"// before: custom factory returns a reference node for a struct\npublic override IObjectNode CreateObjectNode(...) => new ObjectNode(..., isReference: true);\n// after: let the default factory box value types\nvar content = descriptor.Type.IsValueType\n    ? NodeFactory.CreateBoxedNode(this, rootGuid, obj, descriptor)\n    : NodeFactory.CreateObjectNode(this, rootGuid, obj, descriptor);","handlingStrategy":"validation","validationCode":"if (descriptor.Type.IsValueType && descriptor.IsReference) throw new InvalidOperationException($\"{descriptor.Type} is a struct marked as reference\");","typeGuard":"bool IsValidStructNode(ITypeDescriptor d) => !(d.Type.IsValueType && d.IsReference);","tryCatchPattern":"try { builder.Build(obj); } catch (QuantumConsistencyException ex) { logger.LogError(ex, \"Quantum inconsistency for {Type}\", ex.Object?.GetType()); }","preventionTips":["Never override node factories to mark structs as references","Keep Stride.Core.Quantum and Stride.Core.Assemblies versions in sync","Test graph builds over all struct types in your model"],"tags":["quantum","consistency","type-descriptor"],"backgroundTag":"internal-invariant-violation","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"}