{"record":{"id":"ee72813a00ac0c3d","repo":"stride3d/stride","slug":"entity-must-contain-a-non-null-asset-entity","errorCode":null,"errorMessage":"entity must contain a non-null asset entity.","messagePattern":"entity must contain a non-null asset entity\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/editor/Stride.Assets.Presentation/AssetEditors/EntityHierarchyEditor/ViewModels/EntityViewModel.cs","lineNumber":52,"sourceCode":"    [DebuggerDisplay(\"Entity = {Name}\")]\n    public sealed class EntityViewModel : EntityHierarchyElementViewModel, IEditorDesignPartViewModel<EntityDesign, Entity>, IIsEditableViewModel, IDisposable, IAddChildrenPropertiesProviderViewModel\n    {\n        private EntityHierarchyElementChangePropagator propagator;\n\n        // TODO These models should be pluggable later\n        private readonly ModelComponentViewModel modelComponent;\n        private readonly ParticleSystemComponentViewModel particleComponent;\n        private readonly CameraComponentViewModel cameraComponent;\n\n        private readonly MemberGraphNodeBinding<string> nameNodeBinding;\n        private readonly ObjectGraphNodeBinding<EntityComponentCollection> componentsNodeBinding;\n        private readonly IObjectNode transformationNode;\n        private PrefabViewModel sourcePrefab;\n\n        public EntityViewModel([NotNull] EntityHierarchyEditorViewModel editor, [NotNull] EntityHierarchyViewModel asset, [NotNull] EntityDesign entityDesign)\n            : base(editor, asset, GetOrCreateChildPartDesigns((EntityHierarchyAssetBase)asset.Asset, entityDesign), entityDesign.Entity)\n        {\n            if (entityDesign.Entity == null) throw new ArgumentException(@\"entity must contain a non-null asset entity.\", nameof(entityDesign));\n\n            EntityDesign = entityDesign;\n\n            var assetNode = Editor.NodeContainer.GetOrCreateNode(entityDesign.Entity);\n            nameNodeBinding = new MemberGraphNodeBinding<string>(assetNode[nameof(Entity.Name)], nameof(Name), OnPropertyChanging, OnPropertyChanged, Editor.UndoRedoService);\n            componentsNodeBinding = new ObjectGraphNodeBinding<EntityComponentCollection>(assetNode[nameof(Entity.Components)].Target, nameof(Components), OnPropertyChanging, OnPropertyChanged, Editor.UndoRedoService, false);\n\n            modelComponent = new ModelComponentViewModel(ServiceProvider, this);\n            particleComponent = new ParticleSystemComponentViewModel(ServiceProvider, this);\n            cameraComponent = new CameraComponentViewModel(ServiceProvider, this);\n            transformationNode = Editor.NodeContainer.GetNode(AssetSideEntity.Transform)[nameof(TransformComponent.Children)].Target;\n            transformationNode.ItemChanging += TransformChildrenChanging;\n            transformationNode.ItemChanged += TransformChildrenChanged;\n            RenameCommand = new AnonymousCommand(ServiceProvider, () => IsEditing = true);\n            FocusOnEntityCommand = new AnonymousCommand(ServiceProvider, FocusOnEntity);\n\n            UpdateSourcePrefab();\n            var basePrefabNode = Editor.NodeContainer.GetNode(EntityDesign)[nameof(EntityDesign.Base)];","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/editor/Stride.Assets.Presentation/AssetEditors/EntityHierarchyEditor/ViewModels/EntityViewModel.cs#L34-L70","documentation":"EntityViewModel's constructor requires the supplied EntityDesign to already carry a non-null Entity instance, since the view model immediately builds node bindings against entityDesign.Entity (Name, Components). If the entity is null, the base constructor call itself (GetOrCreateChildPartDesigns / base(..., entityDesign.Entity)) would fail downstream, so the constructor fails fast with an ArgumentException naming the offending parameter.","triggerScenarios":"Calling new EntityViewModel(editor, asset, entityDesign) where entityDesign.Entity == null — e.g. constructing an EntityDesign with its default/empty constructor or deserializing a partial asset part definition and passing it straight to the view model.","commonSituations":"Plugin or custom tooling that creates EntityDesign objects programmatically to inject entities into an entity hierarchy editor; code paths that build design objects before assigning the Entity property; upgrading Stride versions where EntityDesign population changed.","solutions":["Assign entityDesign.Entity = new Entity() (or the intended instance) before constructing the EntityViewModel.","Check entityDesign?.Entity == null at the call site and construct/populate the entity first.","If the design comes from deserialization, verify the source asset part actually contains an entity definition and was fully loaded."],"exampleFix":"// before\nvar design = new EntityDesign();\nvar vm = new EntityViewModel(editor, hierarchy, design); // throws\n// after\nvar design = new EntityDesign(new Entity { Name = \"MyEntity\" });\nvar vm = new EntityViewModel(editor, hierarchy, design);","handlingStrategy":"validation","validationCode":"if (entityDesign == null || entityDesign.Entity == null)\n    throw new ArgumentException(nameof(entityDesign), \"EntityDesign must wrap a non-null Entity before creating an EntityViewModel.\");","typeGuard":"bool IsValidDesign(EntityDesign d) => d?.Entity != null;","tryCatchPattern":"try { var vm = new EntityViewModel(editor, asset, design); }\ncatch (ArgumentException ex) when (ex.ParamName == nameof(entityDesign)) { log.Error(\"EntityDesign has null Entity\", ex); }","preventionTips":["Always construct EntityDesign with its entity argument","Validate design objects after deserialization before binding to view models","Add asserts in asset-import tooling that Entity != null"],"tags":["null-argument","wpf","viewmodel","stride-editor"],"backgroundTag":"null-argument","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}