Type of issue
Code doesn't work
Description
Command (passed as argument as per example):
quotes read --file nofile
Expected (according tutorial):
_File does not exist_ message in console
Actual Result:
FileNotFoundException thrown at runtime
Root cause:
DefaultValueFactory is used for validation in the sample but it is not consistently invoked for provided values.
FileInfo binding always succeeds new FileInfo(...) does not validate existence.
So validation is effectively bypassed.
The tutorial implies:
- custom parsing + validation happens in DefaultValueFactory
- parser will surface errors via result.AddError(...)
But in practice:
- validation is skipped for normal input
- errors appear only later during file access
return new FileInfo("sampleQuotes.txt"); does not validate existence, while the other branch does.
Is DefaultValueFactory really the proper place for validation then? Right now it appears that validation has to be moved out to a separate validation mechanism.
Page URL
https://learn.microsoft.com/en-us/dotnet/standard/commandline/get-started-tutorial
Content source URL
https://github.com/dotnet/docs/blob/main/docs/standard/commandline/get-started-tutorial.md
Document Version Independent Id
fa160b1d-66ed-8c5d-37cd-b7e02443e9f1
Platform Id
0f144444-1ce3-cdf7-87a6-c659d44e08d3
Article author
@gewarren
Metadata
- ID: 7705dc41-7297-0807-7e9c-2e6548c26b84
- PlatformId: 0f144444-1ce3-cdf7-87a6-c659d44e08d3
- Service: dotnet-fundamentals
Related Issues
Type of issue
Code doesn't work
Description
Command (passed as argument as per example):
quotes read --file nofileExpected (according tutorial):
_File does not exist_message in consoleActual Result:
FileNotFoundExceptionthrown at runtimeRoot cause:
DefaultValueFactoryis used for validation in the sample but it is not consistently invoked for provided values.FileInfobinding always succeedsnew FileInfo(...)does not validate existence.So validation is effectively bypassed.
The tutorial implies:
But in practice:
return new FileInfo("sampleQuotes.txt");does not validate existence, while the other branch does.Is
DefaultValueFactoryreally the proper place for validation then? Right now it appears that validation has to be moved out to a separate validation mechanism.Page URL
https://learn.microsoft.com/en-us/dotnet/standard/commandline/get-started-tutorial
Content source URL
https://github.com/dotnet/docs/blob/main/docs/standard/commandline/get-started-tutorial.md
Document Version Independent Id
fa160b1d-66ed-8c5d-37cd-b7e02443e9f1
Platform Id
0f144444-1ce3-cdf7-87a6-c659d44e08d3
Article author
@gewarren
Metadata
Related Issues