Skip to content

Config binder generator generates uncompilable code when a private nested type is used #90909

Closed

Description

@stephentoub

This compiles fine:

using Microsoft.Extensions.Configuration;

internal class Program
{
    private static void Main() { }

    private static C Foo(IConfiguration configuration)
    {
        C c = new();
        configuration.Bind(c);
        return c;
    }

    internal sealed class C
    {
        public int Value { get; set; }
    }
}

but changing:

internal sealed class C

to

private sealed class C

produces an error about C being inaccessible, as the generator emits code into another class that tries to access that property.

Activity

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

    @layomia
    Contributor

    I'd say the resolution would be to emit a diagnostic & omit code to support inaccessible members.

  6. ghost added
    in-pr
    on Sep 6, 2023
  7. ghost removed
    in-pr
    on Sep 7, 2023
  8. layomia commented on Sep 7, 2023

    @layomia
    Contributor

    Needs RC-2 port of #91657.

  9. reopened this on Sep 7, 2023
  10. layomia commented on Sep 15, 2023

    @layomia
    Contributor

    Fixed for RC 2 - #91967.

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

Metadata

Metadata

Assignees

Labels

area-Extensions-Configurationblocking-releasebugsource-generator

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions