Closed
Description
This code without the generator:
using Microsoft.Extensions.Configuration;
Environment.SetEnvironmentVariable("Value", "42");
IConfiguration b = new ConfigurationBuilder().AddEnvironmentVariables().Build();
Base d = new Derived();
b.Bind(d);
Console.WriteLine(d.Value);
internal abstract class Base
{
public int Value { get; set; }
}
internal sealed class Derived : Base { }
prints 42
.
With the config generator, that same code throws an exception, because the generator emits this:
public static void Bind_Base(this IConfiguration configuration, object? obj)
{
throw new InvalidOperationException("Cannot create instance of type '<global namespace>.Base' because it is missing a public instance constructor.");
}