Fix NullReferenceException when creating a default immutable instance by 0xced · Pull Request #495 · commandlineparser/commandline
When help is requested, the code takes another path
That is correct. But Parser isn't calling the InstanceBuilder.Build . It Fire the Help Screen.
InvokeBuild in Test call InstanceBuilder.Build .
The Parser still in help request fire InvalidOperationException.
The attached file is a demo project to demonestrate help request with the Immutable class.
ConsoleApp1.zip
run:
Edit:
In case of using InvokeBuild, autohelp parameter should be false.
The next Test case Pass successfully.
[Fact] public void Parse_Immutable_with_default_ctor_and_help__request_throw_InvalidOperationException() { Action act = () => InvokeBuild<ValueWithNoSetterOptions>(new string[] { "--help" }, false); act.Should().Throw<InvalidOperationException>(); }