{"record":{"id":"40a8129ce8de8e6b","repo":"dotnet/BenchmarkDotNet","slug":"list-of-measurements-contains-no-elements","errorCode":null,"errorMessage":"List of measurements contains no elements","messagePattern":"List of measurements contains no elements","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/BenchmarkDotNet/Extensions/ReportExtensions.cs","lineNumber":28,"sourceCode":"        {\n            if (actionExp.Body == null)\n                throw new ArgumentException(\"Extend a an Expression with a valid Body\", nameof(actionExp));\n\n            if (!(actionExp.Body is MethodCallExpression methodExp))\n                throw new ArgumentException(\"Extend a MethodCallExpression, but got a \" + actionExp.Body.GetType().Name, nameof(actionExp));\n\n            return summary.Reports.First(r => r.BenchmarkCase.Descriptor.WorkloadMethod == methodExp.Method);\n        }\n\n        public static IList<Measurement> GetRunsFor<T>(this Summary summary, Expression<Action<T>> actionExp)\n        {\n            return summary.GetReportFor(actionExp).GetResultRuns().ToList();\n        }\n\n        public static Statistics GetStatistics(this IReadOnlyCollection<Measurement> runs)\n        {\n            if (runs.IsEmpty())\n                throw new InvalidOperationException(\"List of measurements contains no elements\");\n            return new Statistics(runs.Select(r => r.GetAverageTime().Nanoseconds));\n        }\n\n        public static Statistics GetStatistics(this IEnumerable<Measurement> runs) =>\n            GetStatistics(runs.ToList());\n\n        public static bool HasError(this IEnumerable<Summary> summaries)\n        {\n            if (summaries.Count() == 0)\n            {\n                // When following argument specified. BenchmarkDotNet show information only.\n                var knownArguments = new HashSet<string>([\"--help\", \"--list\", \"--info\", \"--version\"]);\n                return !Environment.GetCommandLineArgs().Any(knownArguments.Contains);\n            }\n\n            if (summaries.Any(x => x.HasCriticalValidationErrors))\n                return true;\n","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/dotnet/BenchmarkDotNet/blob/b515068b61ad1c9c9aa938b8ece4af1e7d6d85a3/src/BenchmarkDotNet/Extensions/ReportExtensions.cs#L10-L46","documentation":"ReportExtensions.GetStatistics(IReadOnlyCollection<Measurement>) throws InvalidOperationException when the measurement collection is empty. Statistics require at least one sample; an empty list has no meaningful average or deviation, so the library refuses to construct a Statistics instance.","triggerScenarios":"Calling GetStatistics on a collection with zero Measurement items, e.g. summary.GetRunsFor(...).GetStatistics() when the benchmark produced no result runs, or after filtering out all measurements.","commonSituations":"A failed benchmark run (all measurements errored and were excluded), calling GetStatistics on GetResultRuns() of a benchmark that did not execute, or filtering measurements down to nothing before computing statistics.","solutions":["Check runs.Count > 0 (or !runs.IsEmpty()) before calling GetStatistics.","Verify the benchmark actually ran successfully (check BenchmarkReport.Success / HasError) before pulling runs.","If emptiness is legitimate, branch and skip statistics rather than calling the API."],"exampleFix":"// before\nvar stats = runs.GetStatistics();\n\n// after\nvar stats = runs.Count > 0 ? runs.GetStatistics() : null;","handlingStrategy":"validation","validationCode":"var runs = summary.GetRunsFor<MyBench>(b => b.Run());\nStatistics? stats = runs.Count > 0 ? runs.GetStatistics() : null;","typeGuard":null,"tryCatchPattern":"try { var stats = runs.GetStatistics(); }\ncatch (InvalidOperationException) when (runs.Count == 0) { /* no measurements */ }","preventionTips":["Check the benchmark report.Success/HasError before pulling runs.","Guard runs.Count > 0 before computing statistics.","Treat empty runs as an expected branch, not an error, when a benchmark can fail."],"tags":["statistics","validation","reports","measurements"],"backgroundTag":null,"analyzedSha":"b515068b61ad1c9c9aa938b8ece4af1e7d6d85a3","analyzedAt":"2026-08-13T19:12:24.196Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}