dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.61k stars 4.56k forks source link

StackOverflowException in Configuration.Binder source generator #103802

Open bart-vmware opened 3 weeks ago

bart-vmware commented 3 weeks ago

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 https://github.com/dotnet/aspire/pull/4441#discussion_r1648262424_

dotnet-policy-service[bot] commented 3 weeks ago

Tagging subscribers to this area: @dotnet/area-extensions-configuration See info in area-owners.md if you want to be subscribed.