Open harrison314 opened 1 week ago
Tagging subscribers to this area: @dotnet/area-extensions-configuration See info in area-owners.md if you want to be subscribed.
The reflection binder successfully handles this case https://github.com/dotnet/runtime/blob/98e75704a85bfe4a71dd5932c8a2e5f860a09d05/src/libraries/Microsoft.Extensions.Configuration.Binder/src/ConfigurationBinder.cs#L879 We need to ensure the source generator handles that too.
Description
The ConfigurationBinder source generator in the AOT template generates code that doesn’t consider the use of nullable value types like
int
,long
, etc. As a result, binding fails with anInvalidOperationException
because it tries to parse an empty string as anint
in generated code.Microsoft.Extensions.Configuration.Binder.SourceGeneration
version8.0.10.26715
Reproduction Steps
Configuration class:
Binding in Program.cs (ASP web api AOT template):
In appsettings.json:
csproj file:
Expected behavior
In options
LimitSetup.MaxCount
property isnull
value.Actual behavior
I get an exception when binding:
ConfigurationBinder source generator generate this code:
Value
value1
is empty string ifMaxCount
isnull
in appsettings.json.Regression?
No response
Known Workarounds
No response
Configuration
.NET 8 - ASP.NET Core Web API (Native AOT) template
Other information
No response