Configuration binder source generator emits unqualified List<T> when binding arrays without implicit usings

オープン 初心者向け
#136,972 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

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

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
csharp

調査の方向性

gen/Emitter/CoreBindingHelpers.csから始め、特に、issueで修飾されていない型List<T>を出力すると指摘されているEmitBindCoreImplForArrayを確認してください。暗黙のusingを無効にして、提供された再現コードをビルドし、生成されたBindingExtensions.g.csを調べて失敗を確認してください。グローバルusingディレクティブなしで配列のバインディングがコンパイルできれば完了です。また、#121364のテストでこのケースが見逃された理由も調査してください。

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

説明

area-Extensions-Configuration bug source-generator untriaged
Description

The configuration binder source generator produces code that fails to compile when binding an array with implicit usings disabled.

This is a remaining case of #118630: #121364 qualified the generated HashSet<> references, but the temporary List<> used for array binding remains unqualified.

Reproduction Steps

Create these two files and run dotnet build.

repro.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net11.0</TargetFramework>
    <ImplicitUsings>disable</ImplicitUsings>
    <EnableConfigurationBindingGenerator>true</EnableConfigurationBindingGenerator>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Extensions.Configuration.Binder"
                      Version="11.0.0-rc.3.26522.148" />
  </ItemGroup>
</Project>

Program.cs

using Microsoft.Extensions.Configuration;

new ConfigurationBuilder().Build().Get<int[]>();
Expected behavior

The generated code compiles without requiring global using directives from the consuming project.

Actual behavior

The build fails:

BindingExtensions.g.cs(66,29): error CS0246: The type or namespace name 'List<>' could not be found (are you missing a using directive or an assembly reference?)

The generated array-binding method contains:

var temp1 = new List<int>();

The generated file neither imports System.Collections.Generic nor fully qualifies this type.

Regression?

Not a new .NET 11 regression. The original example also fails with Binder 8.0.0, 9.0.0, and 10.0.14, where the unqualified HashSet<> reference causes a compilation error first. The .NET 11 fix removes that error but leaves this array-binding failure.

Known Workarounds

Enable implicit usings, or add:

global using System.Collections.Generic;
Other information

EmitBindCoreImplForArray in gen/Emitter/CoreBindingHelpers.cs emits new List<...>() directly. Fully qualifying that reference would address this case.

When investigating this, also consider looking into why testing of #121364 didn't find this issue.

[!NOTE]
This issue was drafted with GitHub Copilot assistance.

主要言語
C#
スター
18.4k
フォーク
5.8k
平均マージ
2日 15時間
マージ済み PR(30日)
596

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

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

dotnet/runtime のほかの issue

dotnet/runtime の issue をすべて見る

似ている issue

C# の issue をもっと見る

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

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