"Null values preserved in configuration": source generator and in-memory provider statements don't match .NET 9.0.22 / 10.0.14 behavior
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 1/5
- Tiempo estimado
- Menos de una hora
- Aptitud para principiantes
- 86/100
- Tipo de issue
- Documentación
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- csharp
- Área
- documentation
Línea de trabajo
Lee la página de compatibilidad enlazada, especialmente la sección «Non-nullable value types», y compara esa afirmación con la reproducción del problema y el código generado que aparecen en el issue. Corrige la afirmación para que describa cuándo el binder de reflection y el source generator conservan un valor inicial ante valores de configuración nulos o vacíos. La tarea estará terminada cuando la página explique correctamente el comportamiento reportado en .NET 9 y .NET 10.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Page: https://learn.microsoft.com/dotnet/core/compatibility/extensions/10.0/configuration-null-values-preserved (read 2026-11-08)
Statement on the page (section "Non-nullable value types"):
Providers that store a real
nullvalue, such as the in-memory provider, already boundnullto non-nullable value-type properties by setting the default value, even before .NET 10, and the configuration source generator also matches this behavior.
What we observe: neither part holds when the property has an initial value.
Repro (Microsoft.NET.Sdk.Web, TargetFrameworks net9.0;net10.0, built once with EnableConfigurationBindingGenerator false and once with true):
using Microsoft.Extensions.Configuration;
var config = new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string?>
{
["Settings:Name"] = "x",
["Settings:TimeoutSeconds"] = null,
})
.Build();
Settings settings = config.GetSection("Settings").Get<Settings>()!;
Console.WriteLine($"{Environment.Version} TimeoutSeconds = {settings.TimeoutSeconds}");
public sealed class Settings
{
public string? Name { get; set; }
public int TimeoutSeconds { get; set; } = 30;
}
Output (SDK 10.0.403, Windows):
| Binder | .NET 9.0.22 | .NET 10.0.14 |
|---|---|---|
| Reflection | 30 | 0 |
| Source generator | 30 | 30 |
- With the in-memory provider, the reflection binder on .NET 9 kept the initial value (30); it did not set
default(int). - The source generator keeps the initial value on both versions. The generated code assigns a non-nullable value-type property only when the value is neither null nor empty, for example (.NET 10.0.14 generator output):
if (TryGetConfigurationValue(configuration, key: "TimeoutSeconds", out string? value6))
{
if (!string.IsNullOrEmpty(value6))
{
instance.TimeoutSeconds = ParseInt(value6, configuration.GetSection("TimeoutSeconds").Path);
}
}
The same holds for a JSON null (AddJsonFile): reflection binder 0 on .NET 10, source generator 30 on .NET 9 and .NET 10. So on .NET 10 the same configuration produces different values depending on whether the generator is enabled, which matters for apps where it is on by default (AOT web apps, PublishTrimmed).
Suggested fix: remove or correct the sentence, and mention that the source generator does not bind null (or "") to non-nullable value-type properties, so the initial value is kept.
- Lenguaje dominante
- Sin datos de lenguaje
- Estrellas
- 4.8k
- Forks
- 6.1k
- Merge medio
- 1 d 4 h
- PR fusionados (30 d)
- 261
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de dotnet/docs
-
:watch: Not Triaged dotnet/svc
Dificultad 1/5 Menos de una hora Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Improve description of `limitations of extensions`Posiblemente ocupada @Manish-1kumar la tomó hace 8 días. Abiertoadvanced-concepts/subsvc dotnet-csharp/svc
Dificultad 1/5 1-3 horas Aptitud para principiantes 84/100
dotnet/docs#56626 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
dgAbiertodotnet-fundamentals/svc needs-more-info
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
dotnet/docs#56549 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Document unit-test / theory-data impact of .NET 11 double→decimal conversionPosiblemente ocupada @SkyDevLab la tomó hace 19 días. Abierto:watch: Not Triaged dotnet-fundamentals/svc
Dificultad 1/5 1-3 horas Aptitud para principiantes 88/100
Los mantenedores suelen responder en 1 día
-
How to upgrade to `10.0.4xx`?Abiertodotnet-fundamentals/svc install/subsvc
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
dotnet/docs#56344 · 1 comentario · 1 reacción ·
Los mantenedores suelen responder en 1 día
Todos los issues de dotnet/docs
Issues similares
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
stephrobert/dsoxlab#349 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 84/100
objective-see/LuLu#950 ·
-
קישור שבורAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 63/100
nightscout/AndroidAPS#5529 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 84/100
stratum-mining/sv2-spec#253 ·
-
Install page: spectarf's CUDA engine fails with PyTorch for CUDA 13.0 (nvvmError: ERROR_INVALID_IR)Posiblemente ocupada @lukepolson la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 79/100
PyTomography/PyTomography#435 ·
Los mantenedores suelen responder en 1 día