-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Labels
area-Extensions-Configurationbugsource-generatorIndicates an issue with a source generator featureIndicates an issue with a source generator feature
Milestone
Description
Description
Attempting to enable the Configuration binding source generator with a struct used as a custom configuration type causes the source generator to emit code that fails to compile with a CS8598 error.
Repro\Microsoft.Extensions.Configuration.Binder.SourceGeneration\Microsoft.Extensions.Configuration.Binder.SourceGeneration.ConfigurationBindingGenerator\GeneratedConfigurationBinder.g.cs(122,17): error CS8598: The suppression operator is not allowed in this context [Repro\Repro.csproj]
The method generated is below. The failing line is element! = temp4;.
public static void BindCore(IConfiguration configuration, ref IDictionary<string, Geolocation> obj, BinderOptions? binderOptions)
{
if (obj is null)
{
throw new ArgumentNullException(nameof(obj));
}
foreach (IConfigurationSection section in configuration.GetChildren())
{
if (!(obj.TryGetValue(section.Key!, out Geolocation element)))
{
element = InitializeGeolocation(section, binderOptions);;
}
var temp4 = InitializeGeolocation(configuration, binderOptions);;
BindCore(section, ref temp4, binderOptions);
element! = temp4; // CS8598 occurs here
obj[section.Key!] = element;
}
}Reproduction Steps
- Clone martincostello/config-binding-source-generator-cs8598-repro
- Run
dotnet build
Expected behavior
The application compiles and configuration binding works equivalently to runtime binding.
Actual behavior
The application fails to compile with a CS8598 error.
Regression?
No.
Known Workarounds
None.
Configuration
.NET SDK 8.0.100-preview.6.23330.14
Other information
No response
Metadata
Metadata
Assignees
Labels
area-Extensions-Configurationbugsource-generatorIndicates an issue with a source generator featureIndicates an issue with a source generator feature