{"record":{"id":"865d781d0f146d74","repo":"louthy/language-ext","slug":"argumentnullexception-set-internal","errorCode":null,"errorMessage":"ArgumentNullException","messagePattern":"ArgumentNullException","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"LanguageExt.Core/Immutable Collections/Set/Internal/Set.Internal.cs","lineNumber":266,"sourceCode":"    /// <summary>\n    /// Retrieve the value from exact key, or if not found, the next item \n    /// </summary>\n    /// <param name=\"key\">Key to find</param>\n    /// <returns>Found key</returns>\n    [Pure]\n    public Option<A> FindOrSuccessor(A key) => SetModule.TryFindOrSuccessor<OrdA, A>(set, key);\n\n    /// <summary>\n    /// Retrieve a range of values \n    /// </summary>\n    /// <param name=\"keyFrom\">Range start (inclusive)</param>\n    /// <param name=\"keyTo\">Range to (inclusive)</param>\n    /// <exception cref=\"ArgumentNullException\">Throws ArgumentNullException the keyFrom or keyTo are null</exception>\n    /// <returns>Range of values</returns>\n    [Pure]\n    public Iterable<A> FindRange(A keyFrom, A keyTo)\n    {\n        if (isnull(keyFrom)) throw new ArgumentNullException(nameof(keyFrom));\n        if (isnull(keyTo)) throw new ArgumentNullException(nameof(keyTo));\n        return OrdA.Compare(keyFrom, keyTo) > 0\n                   ? SetModule.FindRange<OrdA, A>(set, keyTo, keyFrom).AsIterable()\n                   : SetModule.FindRange<OrdA, A>(set, keyFrom, keyTo).AsIterable();\n    }\n\n\n    /// <summary>\n    /// Returns the elements that are in both this and other\n    /// </summary>\n    [Pure]\n    public SetInternal<OrdA, A> Intersect(IEnumerable<A> other)\n    {\n        var root = SetItem<A>.Empty;\n        foreach (var item in other)\n        {\n            if (Contains(item))\n            {","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/louthy/language-ext/blob/2f0e3628242889774d4141960a35671a0280051f/LanguageExt.Core/Immutable Collections/Set/Internal/Set.Internal.cs#L248-L284","documentation":"Set.FindRange throws ArgumentNullException when keyFrom is null. The set relies on its Ord<A> comparer, which does not accept null keys, so the library validates arguments up front and throws a descriptive ArgumentNullException naming the parameter.","triggerScenarios":"Calling set.FindRange(null, someKey) on a LanguageExt Set.","commonSituations":"Passing nullable values sourced from user input, config, or DB lookups directly into range queries; missing null handling after deserialization.","solutions":["Check both bounds for null before calling FindRange","Filter/throw at the source where the keys are produced","Use FindRangeBetween or an Option-based API if available, handling None for missing bounds","try-catch ArgumentNullException at the boundary if nulls are legitimate inputs"],"exampleFix":"// before\nvar range = set.FindRange(fromKey, toKey);\n// after\nvar range = fromKey != null && toKey != null ? set.FindRange(fromKey, toKey) : Iterable.empty<A>();","handlingStrategy":"validation","validationCode":"if (keyFrom == null || keyTo == null) return Iterable.empty<A>();\nvar range = set.FindRange(keyFrom, keyTo);","typeGuard":"static bool ValidBounds<A>(A from, A to) => from != null && to != null;","tryCatchPattern":"try { range = set.FindRange(from, to); }\ncatch (ArgumentNullException) { range = Iterable.empty<A>(); }","preventionTips":["Null-check range bounds at the query layer","Use Option<A> for optional bounds and pattern-match before querying","Never pass nullable values straight into Ord-based collection APIs"],"tags":["csharp","languageext","set","null-argument"],"backgroundTag":"null-argument","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"}