You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, it seems like the true single file deployment (supported in .NET 5 onwards) is not working properly with BenchmarkDotNet.
Repro
# on Unbuntu 20.04 with latest .NET 5.0 (5.0.4) in PATH
$ dotnet new console -n MyBenchmarkApp
$ cd MyBenchMarkApp
$ dotnet add package BenchmarkDotNet
# write some InProcess benchmarks
$ cat > Program.cs <<EOFusing System;using System.Threading;using BenchmarkDotNet.Attributes;using BenchmarkDotNet.Running;[InProcess]public class Program{ [Benchmark] public void Slow() => Thread.Sleep(100); [Benchmark] public void Fast() => Thread.Sleep(25); static void Main() => BenchmarkRunner.Run<Program>();}EOF# deploy as a singlefile ELF executable (to a dir called ./publish)
$ dotnet publish -c Release -r linux-x64 --self-contained true -p:PublishSingleFile=true -o publish
# first test the (shared) executable which gets generated as part of the build under `./bin`
$ bin/Release/net5.0/linux-x64/MyBenchmarkApp
# ✅ works!# and size of this shared executable
$ du -h bin/Release/net5.0/linux-x64/MyBenchmarkApp
11M bin/Release/net5.0/linux-x64/MyBenchmarkApp
# then try the published app
$ publish/MyBenchmarkApp
# 🛑 fails!
// Validating benchmarks:
// ***** BenchmarkRunner: Start *****
// ***** Found 2 benchmark(s) in total *****
// ***** Building 1 exe(s) in Parallel: Start *****
Failed to generate partition: System.ArgumentNullException: Value cannot be null. (Parameter 'path1')
at System.IO.Path.Combine(String path1, String path2)
at BenchmarkDotNet.Toolchains.InProcess.Emit.InProcessEmitGenerator.GetArtifactsPaths(BuildPartition buildPartition, String rootArtifactsFolderPath)
at BenchmarkDotNet.Toolchains.InProcess.Emit.InProcessEmitGenerator.GenerateProject(BuildPartition buildPartition, ILogger logger, String rootArtifactsFolderPath)
// ***** Done, took 00:00:00 (0.11 sec) *****
// Found 2 benchmarks:
// Program.Slow: InProcess(Toolchain=InProcessEmitToolchain)
// Program.Fast: InProcess(Toolchain=InProcessEmitToolchain)
// Build Error: Exception!
Message: Object reference not set to an instance of an object.,
Stack trace:
at BenchmarkDotNet.Toolchains.Results.BuildResult.Failure(GenerateResult generateResult, Exception exception)
at BenchmarkDotNet.Running.BenchmarkRunnerClean.Build(BuildPartition buildPartition, String rootArtifactsFolderPath, ILogger buildLogger)
// Build Error: Exception!
Message: Object reference not set to an instance of an object.,
Stack trace:
at BenchmarkDotNet.Toolchains.Results.BuildResult.Failure(GenerateResult generateResult, Exception exception)
at BenchmarkDotNet.Running.BenchmarkRunnerClean.Build(BuildPartition buildPartition, String rootArtifactsFolderPath, ILogger buildLogger)
// ***** BenchmarkRunner: Finish *****
...
# and size of this single executable
$ du -h publish/MyBenchmarkApp
77M publish/MyBenchmarkApp
another strange thing is the ./publish directory has more files than expected (in case of a console app without BenchmarkDotNet reference):
$ ls -R publish
publish:
amd64 MyBenchmarkApp MyBenchmarkApp.pdb x86
publish/amd64: // is it necessary on Linux?
KernelTraceControl.dll msdia140.dll
publish/x86: // is it necessary on Linux?
KernelTraceControl.Win61.dll KernelTraceControl.dll msdia140.dll
The text was updated successfully, but these errors were encountered:
Currently, it seems like the true single file deployment (supported in .NET 5 onwards) is not working properly with BenchmarkDotNet.
Repro
another strange thing is the
./publish
directory has more files than expected (in case of a console app without BenchmarkDotNet reference):The text was updated successfully, but these errors were encountered: