Skip to content

StackOverflowException in Configuration.Binder source generator #103802

@bart-vmware

Description

@bart-vmware

Repro steps

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <EnableConfigurationBindingGenerator>true</EnableConfigurationBindingGenerator>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.0" />
  </ItemGroup>
  
</Project>
using Microsoft.Extensions.Configuration;

namespace ClassLibrary7;

public class Class1
{
    public static void Bind(IConfiguration config)
    {
        var supported = new ExampleSettings();
        config.Bind(supported);
    }
}

public record ExampleSettings
{
    /// <summary>
    /// A recursive data structure
    /// </summary>
    public TreeElement? Tree { get; set; }
}

/// <summary>
/// Represents a free-format data structure.
/// </summary>
public sealed class TreeElement : Dictionary<string, TreeElement>;

Expected results

I'd expect the code to compile successfully.

Actual results

This results in a StackOverflowException in the Configuration Binder source generator. When this happens, it locks VS up and you need to force kill it (or let it eventually crash).

Original Description

Can you open an issue (and a PR if you'd like) in https://github.com/dotnet/runtime to get this included in the "real" source generator? As you noted, this is a copy of the runtime code.

Originally posted by @eerhardt in dotnet/aspire#4441 (comment)

Metadata

Metadata

Assignees

Labels

area-Extensions-Configurationin-prThere is an active PR which will close this issue when it is mergedsource-generatorIndicates an issue with a source generator feature

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions