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
Version 0.13.3 breaks LINQPad (and any non-Console application) #2237
Comments
@albahari thank you for the bug report and for the proposed solution! Would you like to send a pull request? cc @timcassell |
I like the class approach, similar to |
Also, keep in mind that the |
Done. I've kept with a single flag, but updated the logic so that it can restore Console.Title on platforms where the property is write-only. |
BenchmarkDotNet 0.13.3 throws an IOException whenever called from LINQPad. The cause is line 171 of BenchmarkRunnerClean:
var consoleTitle = RuntimeInformation.IsWindows() ? Console.Title : string.Empty;
The IOException is thrown when accessing
Console.Title
from a non-Console application in Windows. BenchmarkDotNet is effectively assuming that a Console window will always be available, which is not the case with a Windows Forms, WPF, Windows Service or daemon application. The line of code was introduced by #2140.An easy way to fix this would be to read and restore the Console.Title property only when console output is not redirected. (This will not change the existing behavior because the same check is also performed before updating Console.Title in line 659 and line 674.) To implement this fix requires two changes. First, line 171 is modified as follows:
var consoleTitle = RuntimeInformation.IsWindows() && !Console.IsOutputRedirected ? Console.Title : string.Empty;
We also add the Console.IsOutputRedirected check at line 248:
This will get LINQPad working again (because LINQPad redirects console output). It would also provide a workaround for other non-Console apps that wish to call BenchmarkDotNet (by redirecting Console output).
P.S. If you prefer a cleaner solution, with no repetition of logic, how about introducing a class similar to the following:
Instantiate it in line 171 of BenchmarkRunnerClean as follows:
using var consoleTitler = new ConsoleTitler();
Pass the instance as a parameter where required; no explicit disposal required.
The text was updated successfully, but these errors were encountered: