Skip to content

Config generator emits uncompilable code for certain type conflicts #90976

Closed

Description

@stephentoub

The implementation does name mangling, but those mangled names can conflict with other names, e.g.

using Microsoft.Extensions.Configuration;

IConfiguration configuration = new ConfigurationBuilder().Build();

var c1 = new Cint();
var c2 = new C<int>();
configuration.Bind(c1);
configuration.Bind(c2);

internal class C<T>
{
    public int Value { get; set; }
}

internal class Cint
{
    public int Value { get; set; }
}

Activity

  1. ghost added
    untriaged
    on Aug 23, 2023
  2. added this to the 8.0.0 milestone on Aug 23, 2023
  3. ghost removed
    untriaged
    on Aug 23, 2023
  4. added
    untriaged
    source-generator
    on Aug 23, 2023
  5. self-assigned this
    on Aug 23, 2023
  6. layomia commented on Aug 23, 2023

    @layomia
    Contributor

    I'll resolve with a shared abstraction doing whatever JSON does here.

  7. added and removed
    untriaged
    on Aug 23, 2023
  8. layomia commented on Aug 23, 2023

    @layomia
    Contributor

    Inlining this scenario from #90969:


    e.g.

    namespace S1
    {
        class C1
        {
            public void M(IConfiguration configuration)
            {
                var c = new C1();
                configuration.Bind(c);
            }
        }
    }
    namespace S2
    {
        class C1
        {
            public void M(IConfiguration configuration)
            {
                var c = new C1();
                configuration.Bind(c);
            }
        }
    }

    results in lots of errors like:

    error CS0111: Type 'BindingExtensions' already defines a member called 'Bind_C1' with the same parameter types
    
  9. ericstj commented on Sep 8, 2023

    @ericstj
    Member

    Fixed in #91657

  10. ghost locked as resolved and limited conversation to collaborators on Oct 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-Extensions-Configurationblocking-releasebugsource-generator

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions