{"record":{"id":"d334d9941cf1ac2c","repo":"sschmid/Entitas","slug":"contextentityindexdoesnotexistexception-this-name","errorCode":null,"errorMessage":"ContextEntityIndexDoesNotExistException(this, name)","messagePattern":"ContextEntityIndexDoesNotExistException\\(this, name\\)","errorType":"exception","errorClass":"ContextEntityIndexDoesNotExistException","httpStatus":null,"severity":"error","filePath":"src/Entitas/Context/Context.cs","lineNumber":287,"sourceCode":"\n            return group;\n        }\n\n        /// Adds the IEntityIndex for the specified name.\n        /// There can only be one IEntityIndex per name.\n        public void AddEntityIndex(IEntityIndex entityIndex)\n        {\n            if (_entityIndexes.ContainsKey(entityIndex.Name))\n                throw new ContextEntityIndexDoesAlreadyExistException(this, entityIndex.Name);\n\n            _entityIndexes.Add(entityIndex.Name, entityIndex);\n        }\n\n        /// Gets the IEntityIndex for the specified name.\n        public IEntityIndex GetEntityIndex(string name)\n        {\n            if (!_entityIndexes.TryGetValue(name, out var entityIndex))\n                throw new ContextEntityIndexDoesNotExistException(this, name);\n\n            return entityIndex;\n        }\n\n        /// Resets the creationIndex back to 0.\n        public void ResetCreationIndex() => _creationIndex = 0;\n\n        /// Clears the componentPool at the specified index.\n        public void ClearComponentPool(int index) => _componentPools[index]?.Clear();\n\n        /// Clears all componentPools.\n        public void ClearComponentPools()\n        {\n            for (var i = 0; i < _componentPools.Length; i++)\n                ClearComponentPool(i);\n        }\n\n        /// Resets the context (destroys all entities and","sourceCodeStart":269,"sourceCodeEnd":305,"githubUrl":"https://github.com/sschmid/Entitas/blob/37547d1bd280f3f1c1ef7edb44f2a206660fbfb4/src/Entitas/Context/Context.cs#L269-L305","documentation":"GetEntityIndex looks up an IEntityIndex by name in the context's registry and throws when no index was registered under that name — the requested index simply does not exist (yet).","triggerScenarios":"Calling context.GetEntityIndex(\"MyIndex\") before AddEntityIndex was called for that name, or with a typo'd/renamed index name.","commonSituations":"Querying an index from a different context than the one it was added to, system execution order where the consumer runs before the initializer registers indexes, and index name refactors.","solutions":["Ensure AddEntityIndex for that name runs before GetEntityIndex (fix system init order)","Verify the exact index name string and that you're on the same context instance","Use TryGetEntityIndex / HasEntityIndex-style check if available, or wrap in a check"],"exampleFix":"// before\nvar idx = context.GetEntityIndex(\"UserById\"); // throws if never added\n// after\nif (context.GetEntityIndex(\"UserById\") is var idx && idx != null) { /* use */ }\nelse context.AddEntityIndex(new PrimaryEntityIndex<Entity, string>(\"UserById\", ...));","handlingStrategy":"try-catch","validationCode":"// ensure index exists before use\ncontext.AddEntityIndex(new PrimaryEntityIndex<Entity, string>(\"UserById\", e => e.id));\nvar idx = context.GetEntityIndex(\"UserById\");","typeGuard":null,"tryCatchPattern":"IEntityIndex idx;\ntry { idx = context.GetEntityIndex(\"UserById\"); }\ncatch { throw new InvalidOperationException(\"Index 'UserById' not registered — initialize indexes before use\"); }","preventionTips":["Register all indexes in a single init step that runs first","Centralize index name constants","Verify same context instance when sharing across systems"],"tags":["entitas","entity-index","missing-registration"],"backgroundTag":"resource-not-found","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"}