Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.FormatException in AfterAssemblyLoadingAttached #1536

Open
aaubry opened this issue Sep 17, 2020 · 2 comments
Open

System.FormatException in AfterAssemblyLoadingAttached #1536

aaubry opened this issue Sep 17, 2020 · 2 comments

Comments

@aaubry
Copy link

@aaubry aaubry commented Sep 17, 2020

When I have a MsBuildArgument whose value ends in a backslash, there is an error somewhere along the intermediate code generation that causes the generated program to receive malformed arguments, resulting in a parsing exception. Here's an example of such:

var summary = BenchmarkRunner.Run<MyBenchmark>(DefaultConfig.Instance
    .AddJob(Job.Default
        .WithArguments(new[]
        {
            new MsBuildArgument(@"/p:a=b\"),
        })
    )
);

Attemptig to run this benchmark causes the following error:

// Validating benchmarks:
// ***** BenchmarkRunner: Start   *****
// ***** Found 1 benchmark(s) in total *****
// ***** Building 1 exe(s) in Parallel: Start   *****
BuildScript: C:\src\Experiments\BenchmarkDotNetArguments\bin\Release\net461\5e1c23e7-7d7a-445f-a530-12b4e2027258.bat
// ***** Done, took 00:00:20 (20.03 sec)   *****
// Found 1 benchmarks:
//   MyBenchmark.DoNothing: Job-EWOGGX(Arguments=/p:a=b\)

// **************************
// Benchmark: MyBenchmark.DoNothing: Job-EWOGGX(Arguments=/p:a=b\)
// *** Execute ***
// Launch: 1 / 1
// Execute: C:\src\Experiments\BenchmarkDotNetArguments\bin\Release\net461\5e1c23e7-7d7a-445f-a530-12b4e2027258.exe --benchmarkName "BenchmarkDotNetArguments.MyBenchmark.DoNothing" --job "Arguments=/p:a=b\" --benchmarkId 0 in
// BeforeAnythingElse

System.FormatException: Input string was not in a correct format.
   at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
   at BenchmarkDotNet.Autogenerated.UniqueProgramName.AfterAssemblyLoadingAttached(String[] args)
// AfterAll
ExitCode != 0
// Benchmark Process 60508 has exited with code -1
No more Benchmark runs will be launched as NO measurements were obtained from the previous run!

(...)

I was able to pause the porgram before it compiled the .notcs file and add the following line before it parses the arguments:

for(int i = 0; i < args.Length; ++i) System.Console.WriteLine("{0}: '{1}'", i, args[i]);

This outputs the following,

0: '--benchmarkName'
1: 'BenchmarkDotNetArguments.MyBenchmark.DoNothing'
2: '--job'
3: 'Arguments=/p:a=b" --benchmarkId 0'

which confirms that the arguments are not being passed correctly. There's probably some escaping needed somewhere along the toolchain.

A workaround is to add a summy parameter that does not end with a backslash.

@adamsitnik
Copy link
Member

@adamsitnik adamsitnik commented Sep 17, 2020

Hi @aaubry

Thank you for the detailed bug report.

Would you be interested in sending a PR with a fix?

It should be a matter of fixing the Escape method which is called from here:

public string ToArguments() => $"--benchmarkName {FullBenchmarkName.Escape()} --job {JobId.Escape()} --benchmarkId {Value}";

@aaubry
Copy link
Author

@aaubry aaubry commented Sep 17, 2020

I'll try. Thanks for indicating the location where the arguments are escaped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.