Async lambda (ARCH107)
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
Key dotnet.async.async-lambda · Severity warning · Category async
Async lambdas that bind to an async void signature are dangerous; exceptions inside them cannot be caught. Add proper error handling, or prefer Task-returning delegates.
Incorrect
Section titled “Incorrect”timer.Elapsed += async (s, e) =>{ await _repository.SaveAsync();};Correct
Section titled “Correct”timer.Elapsed += async (s, e) =>{ try { await _repository.SaveAsync(); } catch (Exception ex) { _logger.LogError(ex, "Save failed"); }};Wrap the async lambda body in try/catch, or switch to a Func<Task> delegate. If needed, suppress the rule per project/workspace via except/ignore.