{"record":{"id":"fb782b7a4886f88e","repo":"Unity-Technologies/ml-agents","slug":"enumerator-not-started","errorCode":null,"errorMessage":"Enumerator not started.","messagePattern":"Enumerator not started\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"com.unity.ml-agents/Runtime/Actuators/ActionSegment.cs","lineNumber":215,"sourceCode":"                m_Current = arraySegment.Offset - 1;\n            }\n\n            public bool MoveNext()\n            {\n                if (m_Current < m_End)\n                {\n                    m_Current++;\n                    return m_Current < m_End;\n                }\n                return false;\n            }\n\n            public T Current\n            {\n                get\n                {\n                    if (m_Current < m_Start)\n                        throw new InvalidOperationException(\"Enumerator not started.\");\n                    if (m_Current >= m_End)\n                        throw new InvalidOperationException(\"Enumerator has reached the end already.\");\n                    return m_Array[m_Current];\n                }\n            }\n\n            object IEnumerator.Current => Current;\n\n            void IEnumerator.Reset()\n            {\n                m_Current = m_Start - 1;\n            }\n\n            public void Dispose()\n            {\n            }\n        }\n    }","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/Unity-Technologies/ml-agents/blob/3ecb446f75d1e7400eb404c562dc005d3164cffc/com.unity.ml-agents/Runtime/Actuators/ActionSegment.cs#L197-L233","documentation":"The ActionSegment<T>.Enumerator's Current getter throws InvalidOperationException when the enumerator has not been started, i.e. Current is accessed before the first MoveNext() call (m_Current < m_Start). This mirrors standard .NET enumerator semantics and indicates misuse of the enumeration protocol.","triggerScenarios":"Accessing enumerator.Current (or foreach underlying misuse) without calling MoveNext() first, or manually resetting with Reset() then reading Current before MoveNext().","commonSituations":"Custom iteration code that grabs Current immediately after GetEnumerator(); implementing manual enumerator loops instead of using foreach.","solutions":["Call MoveNext() before reading Current","Use a foreach loop instead of manual enumerator handling","If using Reset(), always MoveNext() again before reading Current"],"exampleFix":"// before\nvar e = actions.GetEnumerator();\nvar first = e.Current;\n// after\nvar e = actions.GetEnumerator();\nif (e.MoveNext()) { var first = e.Current; }","handlingStrategy":"try-catch","validationCode":"var e = actions.GetEnumerator();\nif (e.MoveNext()) { var v = e.Current; }","typeGuard":null,"tryCatchPattern":"try { var v = e.Current; } catch (InvalidOperationException) { /* enumerator not started; call MoveNext */ }","preventionTips":["Prefer foreach over manual enumerators","Always call MoveNext() before reading Current","After Reset(), MoveNext() before Current"],"tags":["unity","ml-agents","enumerator","invalid-operation"],"backgroundTag":"enumerator-misuse","analyzedSha":"3ecb446f75d1e7400eb404c562dc005d3164cffc","analyzedAt":"2026-09-02T16:33:12.832Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}