I am trying to migration some (working) configuration code to use the new configuration source binding generator. However, the source generator never initializes the properties of the configuration object, and no warning or error is generated to highlight the issue.
Reproduction Steps
Configuration section:
public class SqlServerSettings
{
public int? CompatibilityLevel { get; init; }
}
Description
I am trying to migration some (working) configuration code to use the new configuration source binding generator. However, the source generator never initializes the properties of the configuration object, and no warning or error is generated to highlight the issue.
Reproduction Steps
Configuration section:
Usage:
appSettings.json:
Expected behavior
Ideally,
GetCompatibilityLevel
should return130
(probably impossible).Alternatively, a compiler warning / error should be issued to highlight the fact that the source generator cannot set
init
-only properties.Actual behavior
GetCompatibilityLevel
returns0
.The generated
BindCore
method does not attempt to set any properties:No errors or warnings are issued.
Regression?
No response
Known Workarounds
Changing the
init
-only property to a writeable property restores the correct behaviour.Configuration
.NET SDK: Version: 8.0.400 Commit: 36fe6dda56 Workload version: 8.0.400-manifests.6c274a57 MSBuild version: 17.11.3+0c8610977
Runtime Environment: OS Name: Windows OS Version: 10.0.22631 OS Platform: Windows RID: win-x64 Base Path: C:\Program Files\dotnet\sdk\8.0.400\
Visual Studio 2022 v17.11.3
Other information
Possibly related to #92638?