Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Property with init-only setter results in MissingMethodException

オープン
#890 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
42/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
csharp
領域
cli

調査の方向性

CommandLine.Core.InstanceBuilder.Build のスタックトレースから始め、リンク先の .NET Fiddle にある init-only property のケースを再現します。Parser.ParseArguments が options インスタンスをどのように作成するかを追跡し、その後、init-only setter を持つ Options 型の解析が MissingMethodException なしで完了することを確認します。

索引モデルが issue の本文から書いたものです。

説明

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)
主要言語
C#
スター
4.8k
フォーク
478
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

commandlineparser/commandline のほかの issue

commandlineparser/commandline の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。