声明构造函数时无法运行基准测试



我是基准测试的新手,我正在尝试对我的控制器端点进行基准测试,但是我得到了一个错误BenchmarkDotNet has failed to build the auto-generated boilerplate code.,当我在没有类构造函数的情况下运行一些测试时,一切都运行顺利…我一定是做错了什么…

(我已经为依赖注入创建了一个启动类)

benchmark类

[MemoryDiagnoser]
public class UserController
{
private readonly UsersController _controller;
// when I comment this out everything runs smoothly...
/*public UserController(ApplicationDbContext context, IWebHostEnvironment hostingEnvironment) 
{
_controller = new UsersController(context, hostingEnvironment);
}*/
[Benchmark]
public async Task LoginUserErrorAsync()
{
var test = ("kibkjbc").Substring(2);
// await _controller.LoginUserAsync();
}
}

项目类

internal class Program
{
static void Main(string[] args)
{
var config = new ManualConfig()
.WithOptions(ConfigOptions.DisableOptimizationsValidator)
.AddValidator(JitOptimizationsValidator.DontFailOnError)
.AddLogger(ConsoleLogger.Default)
.AddColumnProvider(DefaultColumnProviders.Instance);
BenchmarkRunner.Run<UserController>(config);
}
}

完整错误输出

// Build Error: Standard output:
Standard error:
MSBuild version 17.4.0+18d5aef85 for .NET
C:UsersHoizensourcereposPrestigeServerPrestigeServer.BenchmarkbinReleasenet7.01846966c-92e8-4ff7-aca2-8664b906401eBenchmarkDotNet.Autogenerated.csproj : warning NU1701: Package 'ImageProcessor 2.9.1' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8, .NETFramework,Version=v4.8.1' instead of the project target framework 'net7.0'. This package may not be fully compatible with your project.
C:UsersHoizensourcereposPrestigeServerPrestigeServer.BenchmarkbinReleasenet7.01846966c-92e8-4ff7-aca2-8664b906401eBenchmarkDotNet.Autogenerated.csproj : warning NU1701: Package 'ImageProcessor.Plugins.WebP 1.3.0' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8, .NETFramework,Version=v4.8.1' instead of the project target framework 'net7.0'. This package may not be fully compatible with your project.
C:UsersHoizensourcereposPrestigeServerPrestigeServer.BenchmarkbinReleasenet7.01846966c-92e8-4ff7-aca2-8664b906401eBenchmarkDotNet.Autogenerated.csproj : warning NU1701: Package 'Microsoft.AspNet.WebApi.Core 5.2.9' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8, .NETFramework,Version=v4.8.1' instead of the project target framework 'net7.0'. This package may not be fully compatible with your project.
C:UsersHoizensourcereposPrestigeServerPrestigeServer.BenchmarkbinReleasenet7.01846966c-92e8-4ff7-aca2-8664b906401e1846966c-92e8-4ff7-aca2-8664b906401e.notcs(189,16): error CS7036: There is no argument given that corresponds to the required parameter 'context' of 'UserController.UserController(ApplicationDbContext, IWebHostEnvironment)' [C:UsersHoizensourcereposPrestigeServerPrestigeServer.BenchmarkbinReleasenet7.01846966c-92e8-4ff7-aca2-8664b906401eBenchmarkDotNet.Autogenerated.csproj]
Build FAILED.
C:UsersHoizensourcereposPrestigeServerPrestigeServer.BenchmarkbinReleasenet7.01846966c-92e8-4ff7-aca2-8664b906401eBenchmarkDotNet.Autogenerated.csproj : warning NU1701: Package 'ImageProcessor 2.9.1' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8, .NETFramework,Version=v4.8.1' instead of the project target framework 'net7.0'. This package may not be fully compatible with your project.
C:UsersHoizensourcereposPrestigeServerPrestigeServer.BenchmarkbinReleasenet7.01846966c-92e8-4ff7-aca2-8664b906401eBenchmarkDotNet.Autogenerated.csproj : warning NU1701: Package 'ImageProcessor.Plugins.WebP 1.3.0' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8, .NETFramework,Version=v4.8.1' instead of the project target framework 'net7.0'. This package may not be fully compatible with your project.
C:UsersHoizensourcereposPrestigeServerPrestigeServer.BenchmarkbinReleasenet7.01846966c-92e8-4ff7-aca2-8664b906401eBenchmarkDotNet.Autogenerated.csproj : warning NU1701: Package 'Microsoft.AspNet.WebApi.Core 5.2.9' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8, .NETFramework,Version=v4.8.1' instead of the project target framework 'net7.0'. This package may not be fully compatible with your project.
C:UsersHoizensourcereposPrestigeServerPrestigeServer.BenchmarkbinReleasenet7.01846966c-92e8-4ff7-aca2-8664b906401e1846966c-92e8-4ff7-aca2-8664b906401e.notcs(189,16): error CS7036: There is no argument given that corresponds to the required parameter 'context' of 'UserController.UserController(ApplicationDbContext, IWebHostEnvironment)' [C:UsersHoizensourcereposPrestigeServerPrestigeServer.BenchmarkbinReleasenet7.01846966c-92e8-4ff7-aca2-8664b906401eBenchmarkDotNet.Autogenerated.csproj]
3 Warning(s)
1 Error(s)
Time Elapsed 00:00:03.73
// BenchmarkDotNet has failed to build the auto-generated boilerplate code.
// It can be found in C:UsersHoizensourcereposPrestigeServerPrestigeServer.BenchmarkbinReleasenet7.01846966c-92e8-4ff7-aca2-8664b906401e
// Please follow the troubleshooting guide: https://benchmarkdotnet.org/articles/guides/troubleshooting.html

BenchmarkDotNet需要一个默认构造函数来实例化类。关于如何使用DI设置基准测试,请查看以下内容。

相关内容

  • 没有找到相关文章

最新更新