"Null values preserved in configuration": source generator and in-memory provider statements don't match .NET 9.0.22 / 10.0.14 behavior
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 1/5
- Thời gian dự kiến
- Dưới một giờ
- Mức phù hợp với người mới
- 86/100
- Loại issue
- Tài liệu
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- csharp
- Lĩnh vực
- documentation
Hướng nghiên cứu
Đọc trang tương thích được liên kết, đặc biệt là mục “Non-nullable value types”, rồi so sánh nhận định đó với bản tái hiện và mã được tạo trong issue. Sửa nhận định để mô tả thời điểm reflection binder và source generator giữ nguyên giá trị ban đầu khi giá trị cấu hình là null hoặc rỗng. Hoàn tất khi trang giải thích chính xác hành vi được báo cáo trong .NET 9 và .NET 10.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Không có dữ liệu ngôn ngữ
- Star
- 4.8k
- Fork
- 6.1k
- Merge trung bình
- 1 ngày 1 giờ
- Pull request đã merge (30 ngày)
- 305
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của dotnet/docs
-
Update the .NET Framework 3.5 on Windows 11 FAQ to mention Windows 11 26H2Có thể đã có người làm @BillWagner đã nhận hôm nay. Đang mở:world_map: reQUEST dotnet/svc
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
dotnet/docs#56791 · 1 reaction · 2 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Improve description of `limitations of extensions`Có thể đã có người làm @Manish-1kumar đã nhận 8 ngày trước. Đang mởadvanced-concepts/subsvc dotnet-csharp/svc
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 84/100
dotnet/docs#56626 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
dgĐang mởdotnet-fundamentals/svc needs-more-info
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
dotnet/docs#56549 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Document unit-test / theory-data impact of .NET 11 double→decimal conversionCó thể đã có người làm @SkyDevLab đã nhận 19 ngày trước. Đang mở:watch: Not Triaged dotnet-fundamentals/svc
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày
-
How to upgrade to `10.0.4xx`?Đang mởdotnet-fundamentals/svc install/subsvc
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
dotnet/docs#56344 · 1 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
area/access-management Frontend onboarding candidate :handshake:
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Altinn/altinn-auth#4941 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
hermes-queue
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 91/100
chrisalunlloyd2-sudo/mindpalace#373 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
ACK_WAITING HELP_WANTED UPDATE_CS
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
OWASP/CheatSheetSeries#2935 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
type:docs
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
jejjohnson/xtremax#123 ·