{"record":{"id":"c17ed0791374476e","repo":"sschmid/Entitas","slug":"contextinfoexception-this-contextinfo","errorCode":null,"errorMessage":"ContextInfoException(this, contextInfo)","messagePattern":"ContextInfoException\\(this, contextInfo\\)","errorType":"exception","errorClass":"ContextInfoException","httpStatus":null,"severity":"error","filePath":"src/Entitas/Context/Context.cs","lineNumber":92,"sourceCode":"        readonly EntityEvent _OnEntityReleasedDelegate;\n        readonly EntityEvent _OnDestroyEntityDelegate;\n\n        /// The preferred way to create a context is to use the generated methods\n        /// from the code generator, e.g. var context = new MainContext();\n        public Context(int totalComponents, Func<TEntity> entityFactory) : this(totalComponents, 0, null, null, entityFactory) { }\n\n        /// The preferred way to create a context is to use the generated methods\n        /// from the code generator, e.g. var context = new GameContext();\n        public Context(int totalComponents, int startCreationIndex, ContextInfo contextInfo, Func<Entity, IAERC> aercFactory, Func<TEntity> entityFactory)\n        {\n            _totalComponents = totalComponents;\n            _creationIndex = startCreationIndex;\n\n            if (contextInfo != null)\n            {\n                _contextInfo = contextInfo;\n                if (contextInfo.ComponentNames.Length != totalComponents)\n                    throw new ContextInfoException(this, contextInfo);\n            }\n            else\n            {\n                var componentNames = new string[_totalComponents];\n                for (var i = 0; i < componentNames.Length; i++)\n                    componentNames[i] = \"Index \" + i;\n\n                _contextInfo = new ContextInfo(\"Unnamed Context\", componentNames, null);\n            }\n\n            _aercFactory = aercFactory ?? SafeAERC.Delegate;\n            _entityFactory = entityFactory;\n\n            _groupsForIndex = new List<IGroup<TEntity>>[totalComponents];\n            _componentPools = new Stack<IComponent>[totalComponents];\n            _entityIndexes = new Dictionary<string, IEntityIndex>();\n\n            var groupChangedListPool = new Stack<List<GroupChanged<TEntity>>>();","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/sschmid/Entitas/blob/37547d1bd280f3f1c1ef7edb44f2a206660fbfb4/src/Entitas/Context/Context.cs#L74-L110","documentation":"When a custom ContextInfo (with component names) is passed to the Context constructor, its ComponentNames array length must exactly equal totalComponents. Entitas validates this because component names are indexed by component index; a mismatch would produce wrong or missing names.","triggerScenarios":"new Context<MyEntity>(numComponents, 0, new ContextInfo(\"Game\", new[] { \"Position\", \"Velocity\" }, componentTypes)) where ComponentNames.Length != totalComponents.","commonSituations":"Manually maintained ContextInfo not updated after adding/removing a component class, code-gen config changes, or reusing one ContextInfo across contexts with different totalComponents counts.","solutions":["Ensure ComponentNames.Length equals the totalComponents argument","Regenerate or update ContextInfo after changing the component list","Let contextInfo be null (auto-generates \"Index N\" names) if you don't need custom names"],"exampleFix":"// before\nnew Context<Entity>(3, 0, new ContextInfo(\"Game\", new[] { \"A\", \"B\" }, types)); // 2 names vs 3 components\n// after\nnew Context<Entity>(3, 0, new ContextInfo(\"Game\", new[] { \"A\", \"B\", \"C\" }, types));","handlingStrategy":"validation","validationCode":"if (contextInfo != null && contextInfo.ComponentNames.Length != totalComponents)\n    throw new ArgumentException(\"ComponentNames length must equal totalComponents\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Generate ContextInfo from the same source as component list","Assert lengths in a test","Avoid hand-maintained duplicate component name lists"],"tags":["entitas","context","config-mismatch"],"backgroundTag":"schema-validation-failed","analyzedSha":"37547d1bd280f3f1c1ef7edb44f2a206660fbfb4","analyzedAt":"2026-09-14T00:26:23.246Z","contentChangedAt":"2026-09-14T00:26:23.246Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}