Skip to content

Configuration Binder source generator can generate code that won't compile #111517

Closed

Description

@keegan-caruso

Description

The configuration binder source generator can generate code that won't compile. It can generate code of the form new (value1, value2)()

Which gives an error of: 'new' cannot be used with tuple type. Use a literal expression instead.

Reproduction Steps

Enable source generated configuration binder:

<EnableConfigurationBindingGenerator>true</EnableConfigurationBindingGenerator>

Try to bind a class that has a getter that includes a property of the class in a value tuple.

    public class ExampleOptions
    {
        public List<string> ExampleCollection { get; set; }

        internal List<(string, ICollection<string>?)> UsesCollection =>
                [
                    ("Label-1", ExampleCollection )
                ];
    }

    builder.Services.Configure<ExampleOptions>("Repro", builder.Configuration.GetSection("Repro"));

The generated code that fails to compile:

        public static void BindCore(IConfiguration configuration, ref global::System.Collections.Generic.List<(string, global::System.Collections.Generic.ICollection<string>)> instance, bool defaultValueIfNotFound, BinderOptions? binderOptions)
        {
            foreach (IConfigurationSection section in configuration.GetChildren())
            {
                if (!string.IsNullOrEmpty(section.Value) && !section.GetChildren().Any())
                {
                    continue;
                }
                var value = new (string, global::System.Collections.Generic.ICollection<string>)();
                instance.Add(value);
            }
        }

Additionally, is not clear to me why it is generating code to bind against a property that only has a getter.

Expected behavior

The generated code should compile.

Actual behavior

The generated code does not compile.

Regression?

No response

Known Workarounds

No response

Configuration

.NET SDK:
Version: 9.0.102
Commit: cb83cd4923
Workload version: 9.0.100-manifests.221265b2
MSBuild version: 17.12.18+ed8c6aec5

This reproduction was created off of the net9.0 ASP.NET Core Web API template.

The version of Microsoft.Extensions.Configuration.Binder.SourceGeneration used was 9.0.11.11010

Other information

No response

Activity

  1. added
    untriaged
    on Jan 17, 2025
  2. dotnet-policy-service commented on Jan 17, 2025

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-extensions-configuration
    See info in area-owners.md if you want to be subscribed.

  3. added this to the 10.0.0 milestone on Jan 17, 2025
  4. added
    source-generator
    and removed
    untriaged
    on Jan 17, 2025
  5. modified the milestones: 10.0.0, 11.0.0 on Jul 26, 2025
  6. 0xfeeddeadbeef commented on Aug 8, 2025

    @0xfeeddeadbeef

    Is there a workaround for this problem?

  7. rosebyte commented on Mar 6, 2026

    @rosebyte
    Member

    Triage: we will consider fixing it in future.

  8. added a commit that references this issue on Jul 2, 2026
    53ae4be
  9. locked and limited conversation to collaborators on Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-Extensions-Configurationbugsource-generator

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions