{"record":{"id":"47aa1d52db503901","repo":"louthy/language-ext","slug":"key-doesn-t-exist-in-map-key-trieset","errorCode":null,"errorMessage":"Key doesn't exist in map: {key}","messagePattern":"Key doesn't exist in map: (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"LanguageExt.Core/Immutable Collections/TrieSet/TrieSet.cs","lineNumber":241,"sourceCode":"        Sec section = default;\n        var (countDelta, newRoot) = Root.Remove(key, hash, section);\n        return ReferenceEquals(newRoot, Root)\n                   ? this\n                   : new TrieSet<EqK, K>(newRoot, count + countDelta);\n    }\n\n    /// <summary>\n    /// Indexer\n    /// </summary>\n    public K this[K key]\n    {\n        [MethodImpl(MethodImplOptions.AggressiveInlining)]\n        get\n        {\n            var (found, nkey) = FindInternal(key);\n            return found\n                       ? nkey\n                       : throw new ArgumentException($\"Key doesn't exist in map: {key}\");\n        }\n    }\n\n    /// <summary>\n    /// Create an empty map\n    /// </summary>\n    [MethodImpl(MethodImplOptions.AggressiveInlining)]\n    public TrieSet<EqK, K> Clear() =>\n        Empty;\n\n    /// <summary>\n    /// Get the hash code of the items in the map\n    /// </summary>\n    [MethodImpl(MethodImplOptions.AggressiveInlining)]\n    public override int GetHashCode() =>\n        hash == 0\n            ? (hash = FNV32.Hash<EqK, K>(AsEnumerable()))\n            : hash;","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/louthy/language-ext/blob/2f0e3628242889774d4141960a35671a0280051f/LanguageExt.Core/Immutable Collections/TrieSet/TrieSet.cs#L223-L259","documentation":"TrieSet's this[key] indexer finds the stored element equal to key and throws ArgumentException when it is not present. TrieSet is keyed by the elements themselves, so this occurs when you index with a value the set does not contain. Use Find/FindOption for safe access instead of the strict indexer.","triggerScenarios":"Reading set[key] (e.g. set[someValue]) where someValue is not an element of the TrieSet; equality comparer differences making a 'same' value unequal.","commonSituations":"Using TrieSet like a lookup table for values it may not contain; case-sensitive string elements; elements removed before indexing; relying on value-vs-reference equality for custom types.","solutions":["Use Find(key) or FindOption(key) and handle the Option result","Check Contains(key) before indexing","Verify the element's equality semantics (EqK) match your expectations","Use try/catch for ArgumentException only if absence is truly exceptional"],"exampleFix":"// before\nvar item = trieSet[key];\n// after\nvar item = trieSet.FindOption(key).IfNone(fallback);","handlingStrategy":"validation","validationCode":"if (set.Contains(key)) { var v = set[key]; } else { /* handle absence */ }","typeGuard":"bool HasItem<K>(TrieSet<K> s, K key) => s.Contains(key);","tryCatchPattern":"try { var v = set[key]; }\ncatch (ArgumentException) { /* element absent: use fallback */ }","preventionTips":["Prefer Find/FindOption over the indexer","Check Contains before indexing","Account for the set's equality comparer"],"tags":["immutable-collections","set","key-not-found"],"backgroundTag":"resource-not-found","analyzedSha":"2f0e3628242889774d4141960a35671a0280051f","analyzedAt":"2026-09-15T03:31:55.716Z","contentChangedAt":"2026-09-15T03:31:55.716Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}