{"record":{"id":"73ff06c4ebca9db1","repo":"dotnet/reactive","slug":"strings-linq-no-matching-elements","errorCode":null,"errorMessage":"Strings_Linq.NO_MATCHING_ELEMENTS","messagePattern":"Strings_Linq\\.NO_MATCHING_ELEMENTS","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable/FirstAsync.cs","lineNumber":109,"sourceCode":"                        ForwardOnError(ex);\n                        return;\n                    }\n\n                    if (b)\n                    {\n                        _found = true;\n                        ForwardOnNext(value);\n                        ForwardOnCompleted();\n                    }\n                }\n\n                public override void OnCompleted()\n                {\n                    if (!_found)\n                    {\n                        try\n                        {\n                            throw new InvalidOperationException(Strings_Linq.NO_MATCHING_ELEMENTS);\n                        }\n                        catch (Exception e)\n                        {\n                            ForwardOnError(e);\n                        }\n                    }\n                }\n            }\n        }\n    }\n}\n","sourceCodeStart":91,"sourceCodeEnd":121,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable/FirstAsync.cs#L91-L121","documentation":"FirstAsync with a predicate throws InvalidOperationException with Strings_Linq.NO_MATCHING_ELEMENTS when the source completes and no element satisfied the predicate (_found remains false). Forwarded to the observer via OnError.","triggerScenarios":"Subscribing to source.FirstAsync(x => predicate(x)) where no emitted element matches before completion.","commonSituations":"Waiting for a matching status event that never arrives; filtering a stream by a condition that is never true due to a config or data-format mistake.","solutions":["Use FirstOrDefaultAsync(predicate) to get default(T) instead of an error when nothing matches","Catch InvalidOperationException in OnError and fall back","Double-check the predicate logic against the actual data"],"exampleFix":"// before\nsource.FirstAsync(x => x.IsValid).Subscribe(...);\n// after\nsource.FirstOrDefaultAsync(x => x.IsValid).Subscribe(x => ...);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"source.FirstAsync(pred).Subscribe(\n    x => Console.WriteLine(x),\n    ex => { if (ex is InvalidOperationException) Console.WriteLine(default); else throw ex; });","preventionTips":["Prefer FirstOrDefaultAsync(predicate)","Review predicates against real data so they can actually match","Log OnError instead of crashing on no-match"],"tags":["reactive","linq","first","predicate","no-match"],"backgroundTag":"empty-result-set","analyzedSha":"94b5d5ab912789f5abe9a72138a25bbd716fe59c","analyzedAt":"2026-09-15T02:26:24.759Z","contentChangedAt":"2026-09-15T02:26:24.759Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}