|
9 | 9 | using BenchmarkDotNet.Loggers; |
10 | 10 | using BenchmarkDotNet.Reports; |
11 | 11 | using System.Runtime.InteropServices; |
| 12 | +using System.Runtime.CompilerServices; |
12 | 13 |
|
13 | 14 | namespace BenchmarkDotNet.Tests.Running |
14 | 15 | { |
@@ -278,12 +279,13 @@ public void AssemblyWithBenchmarks_RunsSuccessfully_WhenBenchmarkAttributePresen |
278 | 279 | var ilGenerator = benchmarkMethod.GetILGenerator(); |
279 | 280 | ilGenerator.Emit(OpCodes.Ret); // Just return from the method |
280 | 281 |
|
281 | | - var benchmarkAttributeCtor = typeof(BenchmarkAttribute).GetConstructor(new[] { typeof(int), typeof(string) }); |
282 | | - if (benchmarkAttributeCtor == null) |
283 | | - throw new InvalidOperationException("Could not find BenchmarkAttribute constructor"); |
284 | 282 | benchmarkMethod.SetCustomAttribute(new CustomAttributeBuilder( |
285 | | - benchmarkAttributeCtor, |
286 | | - new object[] { 0, "" })); |
| 283 | + typeof(BenchmarkAttribute).GetConstructor([typeof(int), typeof(string)]), |
| 284 | + [0, ""])); |
| 285 | + // Assembly weaver does not run on assemblies created with AssemblyBuilder, so we need to apply NoInlining manually. |
| 286 | + benchmarkMethod.SetCustomAttribute(new CustomAttributeBuilder( |
| 287 | + typeof(MethodImplAttribute).GetConstructor([typeof(MethodImplOptions)]), |
| 288 | + [MethodImplOptions.NoInlining])); |
287 | 289 | benchmarkTypeBuilder.CreateType(); |
288 | 290 |
|
289 | 291 | Summary[] summaries = null; |
|
0 commit comments