Skip to content

ConfigurationBinder source generator emits SYSLIB1100 when it shouldn't apply #93132

Closed

Description

@ericstj

Description

I have a public type with an internal constructor in the same assembly as my bind call.

a. I wouldn't expect the source generator to need to construct the object at all since it's a Bind call.
b. The constructor is internal, which makes it visible to the source generator.

Reproduction Steps

Repro project: internalConstructor.zip

using Microsoft.Extensions.Configuration;

var c = new ConfigurationBuilder()
    .AddInMemoryCollection(new Dictionary<string,string?>()
    {
        ["Value"] = "Hello",
        ["Value2"] = "Hello world"
    })
    .Build();


MyType x = new();
c.Bind(x);
Console.WriteLine(x.Value);
Console.WriteLine(x.Value2);


public class MyType
{
    internal MyType(){ }
    public string? Value { get; set; }
    public string? Value2 { get; set; }
}

Expected behavior

Compiles successfully without warning.

Actual behavior

C:\scratch\internalConstructor\Program.cs(13,1): warning SYSLIB1100: Cannot create instance of type 'MyType' because it
is missing a public instance constructor. (https://learn.microsoft.com/dotnet/fundamentals/syslib-diagnostics/syslib11

  1. [C:\scratch\internalConstructor\internalConstructor.csproj]

Regression?

No

Known Workarounds

Suppress the warning

Configuration

No response

Other information

No response

Activity

  1. ghost added
    untriaged
    on Oct 6, 2023
  2. added this to the 9.0.0 milestone on Oct 6, 2023
  3. ghost removed
    untriaged
    on Oct 6, 2023
  4. added
    untriaged
    source-generator
    on Oct 6, 2023
  5. ghost removed
    untriaged
    on Oct 6, 2023
  6. ericstj commented on Oct 27, 2023

    @ericstj
    MemberAuthor

    I see a lot of folks hitting SYSLIB1100 and SYSLIB1101 for non-root level types - these behave similar to a root level type that's being passed to Bind -- the binder doesn't always need to create a type so the fact that it cannot may not be a worthwhile diagnostic to raise to the user.

    This problem is exacerbated by lack of the ability to granularly suppress these warnings - or suppress at all in source due to #92509.

    I wonder if we should split these diagnostics into two - one set where it's clear that we can't do what the user wanted and another where it's more informational (and not a warning). @tarekgh @eiriktsarpalis @eerhardt

    On the flip side of that - we still end up generating a ton of binding code for members that ultimately might never show up in configuration - take the case where someone had a Func hanging off the configuration type and we end up producing bind logic for a good amount of reflection types.

    I think we might want something like JsonIgnore here, but use it to prevent us from generating bind logic. We already have ConfigurationKeyNameAttribute which can set the name of member, but not attribute to exclude a member. For the runtime binder this might not matter - but for the source gen it's more important.

  7. eiriktsarpalis commented on Oct 27, 2023

    @eiriktsarpalis
    Member

    the binder doesn't always need to create a type so the fact that it cannot may not be a worthwhile diagnostic to raise to the user.

    Guessing that depends on whether the type is present in a nested property or not?

    Even if the binder did need the constructor, is this a valid diagnostic to raise given that the internal constructor is being used regardless? I would only have expected this to complain only if the constructor were inaccessible to the generator.

  8. ericstj commented on Oct 27, 2023

    @ericstj
    MemberAuthor

    What I was discussing above is even broader than the original issue. The internal constructor problem is a plain-old-bug but one that will may be moot if we take the broader look at this behavior.

    My point is that binding to types which are not constructable is actually a very common scenario and doesn't warrant raising a warning.

  9. ericstj commented on Aug 6, 2024

    @ericstj
    MemberAuthor

    Repro in this issue no longer produces a warning. We also fixed our behavior for unsupported types in
    27685cf

  10. locked and limited conversation to collaborators on Sep 7, 2024
  11. agocke commented on Mar 26, 2026

    @agocke
    Member

    @ericstj Azure SDK/MCP is still seeing this warning (and others) in Microsoft.Identity.Abstractions: https://github.com/anuchandy/idweb-source-gen-warns. Any idea what could be going on here, and how we could suppress generation/warnings for these members?

  12. svick commented on Mar 30, 2026

    @svick
    Member

    @agocke I think marking the property as [ConfigurationIgnore] should fix that, if and when that becomes available. See #125111.

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-Configurationsource-generator

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions