{"record":{"id":"cadf4a6447c6ba35","repo":"stride3d/stride","slug":"invalidoperationexception","errorCode":null,"errorMessage":"InvalidOperationException","messagePattern":"InvalidOperationException","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Yaml/SortedDictionary.cs","lineNumber":468,"sourceCode":"\n                    if (getEnumeratorRetType == DictEntry)\n                    {\n                        return new DictionaryEntry(Current.Key, Current.Value);\n                    }\n                    else\n                    {\n                        return new KeyValuePair<TKey, TValue>(Current.Key, Current.Value);\n                    }\n                }\n            }\n\n            object IDictionaryEnumerator.Key\n            {\n                get\n                {\n                    if (NotStartedOrEnded)\n                    {\n                        throw new InvalidOperationException();\n                    }\n\n                    return Current.Key;\n                }\n            }\n\n            object IDictionaryEnumerator.Value\n            {\n                get\n                {\n                    if (NotStartedOrEnded)\n                    {\n                        throw new InvalidOperationException();\n                    }\n\n                    return Current.Value;\n                }\n            }","sourceCodeStart":450,"sourceCodeEnd":486,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Yaml/SortedDictionary.cs#L450-L486","documentation":"IDictionaryEnumerator.Key on SortedDictionary's enumerator throws InvalidOperationException when the enumerator has not been started (MoveNext not yet called) or has already run past the end. There is no current entry to read the key from.","triggerScenarios":"Reading .Key from the IDictionaryEnumerator before calling MoveNext, or after MoveNext returned false.","commonSituations":"Manual non-generic IDictionary enumeration loops that don't check MoveNext's return value or access the key outside the loop body.","solutions":["Call MoveNext and only access Key when it returns true","Reset the enumerator and re-enumerate if you need another pass","Prefer the generic IEnumerator<KeyValuePair<TKey,TValue>> or foreach instead of IDictionaryEnumerator"],"exampleFix":"// before\nvar e = dict.GetEnumerator();\nvar key = ((IDictionaryEnumerator)e).Key; // not started\n// after\nvar e = dict.GetEnumerator();\nif (e.MoveNext()) { var key = ((IDictionaryEnumerator)e).Key; }","handlingStrategy":"type-guard","validationCode":"bool eOk = enumerator is IDictionaryEnumerator de && de.MoveNext(); // position before reading","typeGuard":"bool CanRead(IDictionaryEnumerator e) { /* track: started and not ended */ return started && !ended; }","tryCatchPattern":"try { var key = ((IDictionaryEnumerator)e).Key; } catch (InvalidOperationException) { /* enumerator not positioned; reset and re-enumerate */ e.Reset(); }","preventionTips":["Always loop on MoveNext's return value","Prefer foreach over manual IDictionaryEnumerator","Call Reset before reusing an enumerator"],"tags":["csharp","enumerator","invalid-operation"],"backgroundTag":"invalid-state-transition","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"}