Property with init-only setter results in MissingMethodException
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 42/100
Hướng nghiên cứu
Bắt đầu với stack trace tại CommandLine.Core.InstanceBuilder.Build và tái hiện trường hợp thuộc tính init-only từ .NET Fiddle được liên kết. Theo dõi cách Parser.ParseArguments tạo instance Options, sau đó xác minh rằng việc phân tích cú pháp một kiểu Options có setter init-only hoàn tất mà không có MissingMethodException.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
In case of read-only properties in the command line options class, where a property is defined as
public string Foo
{
get;
init;
}
you will get a MissingMethodException when parsing the command line.
To Reproduce
See this fiddle https://dotnetfiddle.net/J05g0c
Expected behavior
The exception is not thrown
Additional context
The resulting stack trace is as follows:
Unhandled exception. System.MissingMethodException: Cannot dynamically create an instance of type 'Options'. Reason: No parameterless constructor defined.
at System.RuntimeType.ActivatorCache..ctor(RuntimeType rt)
at System.RuntimeType.CreateInstanceOfT()
at System.Activator.CreateInstance[T]()
at CommandLine.Core.InstanceBuilder.<>c__1`1.<Build>b__1_0(Func`1 f)
at CSharpx.MaybeExtensions.MapValueOrDefault[T1,T2](Maybe`1 maybe, Func`2 func, T2 noneValue)
at CommandLine.Core.InstanceBuilder.Build[T](Maybe`1 factory, Func`3 tokenizer, IEnumerable`1 arguments, StringComparer nameComparer, Boolean ignoreValueCase, CultureInfo parsingCulture, Boolean autoHelp, Boolean autoVersion, Boolean allowMultiInstance, IEnumerable`1 nonFatalErrors)
at CommandLine.Parser.ParseArguments[T](IEnumerable`1 args)
at Program.Main(String[] args)
- 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
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
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của commandlineparser/commandline
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
commandlineparser/commandline#951 · 1 bình luận ·
-
Code example misses iEnumerable Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 70/100
commandlineparser/commandline#880 · 2 reaction ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 45/100
commandlineparser/commandline#952 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
commandlineparser/commandline#948 ·
-
How to add examples for verbs? Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
commandlineparser/commandline#947 ·
Tất cả issue của commandlineparser/commandline
Issue tương tự
-
CS0162 "Unreachable code detected" warning from a MSBuildTemp .tmp file in every game project Đang mởbug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
-
Type: enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
apache/arrow-adbc#4809 ·
-
type/automation type/tech-debt
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
microsoft/vscode-azurefunctions#5197 · 1 bình luận ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
microsoft/microsoft-ui-reactor#1274 ·