Skip to content

Conversation

@guardrex
Copy link
Collaborator

@guardrex guardrex commented Feb 11, 2026

Fixes #36665

Tom .....

The in-memory config provider is already covered elsewhere in the the article, so we don't need a rehash of that in the Bind an array section. What we need to do here is just explain that a missing array value can be supplied to config before the array is bound. I retain the content along those lines with some code updates. Also, this really shouldn't be for just <6.0. I guess at the time (when Startup.cs was set aside in favor of doing everything in the Program file) the author (Rick?) was going to circle back around with updates for the scenario, and they just didn't get back to it. It turns out that the approach works in all versions of .NET. I've addressed the 6.0 situation (Startup/Program) with the versioned code examples.


Internal previews

📄 File 🔗 Preview link
aspnetcore/fundamentals/configuration/index.md aspnetcore/fundamentals/configuration/index

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the Bind an array documentation in the ASP.NET Core configuration article to focus on how to supply a missing array element via configuration prior to binding, with version-specific examples for pre-.NET 6 and .NET 6+ hosting models.

Changes:

  • Removes a cross-reference to the in-memory provider example from earlier in the article.
  • Reworks the Bind an array section to show supplying a missing index via an additional configuration provider (JSON), with monikered snippets for < aspnetcore-6.0 and >= aspnetcore-6.0.
  • Simplifies/updates the code and output shown in that section.
Comments suppressed due to low confidence (1)

aspnetcore/fundamentals/configuration/index.md:1253

  • The loop condition j < array.Entries?.Length doesn't compile because array.Entries?.Length is an int?, which makes the comparison produce a bool? (invalid in a for condition). Consider checking array.Entries for null before the loop, or coalescing the length to 0 so the condition is a non-nullable bool.
for (int j = 0; j < array.Entries?.Length; j++)
{
    Console.WriteLine($"Index: {j} Value: {array.Entries[j]}");
}

@guardrex guardrex requested a review from tdykstra February 11, 2026 14:13
@guardrex guardrex self-assigned this Feb 11, 2026
@guardrex guardrex merged commit 0c62ae9 into main Feb 11, 2026
4 checks passed
@guardrex guardrex deleted the guardrex/bind-an-array-in-config-article branch February 11, 2026 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Follow-up on Config article section

2 participants