commandlineparser / commandlineparser/commandline

Console.Error should not be referenced in a static object

Đang mở
#747 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
C#
Star
4.8k
Fork
478
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

Changing the Console.Error throws System.ObjectDisposedException

Console.Error can be changed using Console.SetError() method, so having this as a static reference prevents using the "newly" assigned TextWriter as it keeps the referenced to the original instance which has been disposed.

"Cannot write to a closed TextWriter."
at System.IO.StringWriter.Write(String value)
at System.IO.TextWriter.SyncTextWriter.Write(String value)
at CommandLine.Parser.<>c__DisplayClass17_0`1.b__1(IEnumerable`1 _, TextWriter writer)
at CSharpx.MaybeExtensions.Do[T1,T2](Maybe`1 maybe, Action`2 action)
at CommandLine.Parser.<>c__DisplayClass17_0`1.b__0(IEnumerable`1 errors)
at CommandLine.ParserResultExtensions.WithNotParsed[T](ParserResult`1 result, Action`1 action)
at CommandLine.Parser.DisplayHelp[T](ParserResult`1 parserResult, TextWriter helpWriter, Int32 maxDisplayWidth)
at CommandLine.Parser.MakeParserResult[T](ParserResult`1 parserResult, ParserSettings settings)
at CommandLine.Parser.ParseArguments(IEnumerable`1 args, Type[] types)
at TestApp.Program.Main(String[] args) in Program.cs:line 25
at TestApp.Tests.ProgramTest.Main_ShouldExecuteCommandSuccesfully(List`1 args) in ProgramTest.cs:line 18

https://github.com/commandlineparser/commandline/blob/d443a51aeb3a418425e970542b3b96e9da5f62e2/src/CommandLine/Parser.cs#L22

```c#
private static readonly Lazy DefaultParser = new Lazy(() => new Parser(new ParserSettings { HelpWriter = Console.Error }));
```

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.