Skip to content

Commit 7817814

Browse files
committed
error 'Index was outside the bounds of the array'
1 parent e4fa223 commit 7817814

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/ConsoleAppFramework/ConsoleAppEngine.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,11 @@ bool TryGetInvokeArguments(ParameterInfo[] parameters, string?[] args, int argsO
478478
}
479479
else
480480
{
481+
if (args.Length <= i)
482+
{
483+
throw new ArgumentException($@"Value for parameter ""{key}"" is not provided.");
484+
}
485+
481486
var value = args[i];
482487
dict.Add(key, new OptionParameter { Value = value });
483488
i++;

tests/ConsoleAppFramework.Tests/Integration/SingleCommandTest.Options.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public void OptionalBoolAndRequiredOtherOption_NoArgs_1()
203203
public void Attempt_To_Call_Without_Parameter_Value()
204204
{
205205
using var console = new CaptureConsoleOutput();
206-
var args = new[] { "--hello", "--name" };
206+
var args = new[] { "--name" };
207207
Host.CreateDefaultBuilder().RunConsoleAppFrameworkAsync<CommandTests_Single_OptionalBoolAndRequiredOtherOption_NoArgs>(args);
208208
console.Output.Should().Contain(@"Value for parameter ""name"" is not provided.");
209209
}

0 commit comments

Comments
 (0)