Skip to content

Conversation

@Shrinidhi203
Copy link
Contributor

Fix #2724

Problem

When running 'BenchmarkRunner.Run()' or 'BenchmarkRunner.Run(Type)' with arguments on an invalid benchmark type (no [Benchmark] methods), the runner threw an unhandled 'InvalidOperationException: Sequence contains no elements' instead of returning a validation error.

Solution

  • Replace '.Single()' with '.SingleOrDefault()' in 'RunWithDirtyAssemblyResolveHelper'
  • Return 'Summary.ValidationFailed' with a descriptive message when no benchmarks are found

Changes

  • 'src/BenchmarkDotNet/Running/BenchmarkRunnerDirty.cs' - Fix the exception handling
  • 'tests/BenchmarkDotNet.Tests/Running/RunningEmptyBenchmarkTests.cs' - Enable and update tests

…th arguments

  Fixes dotnet#2724

  When running BenchmarkRunner.Run<T>() or BenchmarkRunner.Run(Type) with
  arguments on an invalid benchmark type (no [Benchmark] methods), the runner
  threw an unhandled InvalidOperationException instead of returning a validation error.

  Changes:
  - Replace .Single() with .SingleOrDefault() in RunWithDirtyAssemblyResolveHelper
  - Return Summary.ValidationFailed when no benchmarks are found
  - Enable and update tests for args scenarios in RunningEmptyBenchmarkTests.cs"
@Shrinidhi203
Copy link
Contributor Author

@dotnet-policy-service agree

@Shrinidhi203
Copy link
Contributor Author

There were StyleCop errors , thats also fixed.

@Shrinidhi203
Copy link
Contributor Author

Have asserted the failure.

Copy link
Collaborator

@timcassell timcassell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Shrinidhi203

@timcassell timcassell merged commit dde78c5 into dotnet:master Nov 29, 2025
9 checks passed
@timcassell timcassell added this to the v0.15.8 milestone Nov 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unhandled Exception Thrown When Running an invalid Type-Based Benchmark with Arguments

2 participants