Skip to content

Binding source generator emits bad code for tuples #115133

Closed
@sbomer

Description

@sbomer

For binding List<(string Error, string MemberName)>, the binding source generator produces code like this:

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

which produces an error:

error CS8181: 'new' cannot be used with tuple type. Use a tuple literal expression instead.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions