Azure / Azure/azure-functions-dotnet-worker

Duplication appsettings.{Environment}.json in configuration sources

Open
#3,329 0 comments 0 reactions 0 assignees View on GitHub
Needs: Triage (Functions) potential-bug
Dominant language
C#
Stars
466
Forks
215
Avg merge
3d 10h
Merged PRs (30d)
7

Description

### Description

### 🔍 Description

in `FunctionsApplication.CreateBuilder(args)`, `HostApplicationBuilder` constructor already applies default host/app configuration and default services in its constructor (when defaults are enabled).
In the current startup flow, `ConfigureDefaults()` is also being invoked, which appears redundant and will cause duplicate/default configuration sources (i.e. appsettings.json and appsettings.{Environment}.json).

This creates confusion about expected hosting setup and could lead to subtle ordering differences compared to intended `HostApplicationBuilder` usage.

### 💡 Expected behavior

When using `HostApplicationBuilder` with defaults enabled, the worker initialization path should not re-apply `IHostBuilder.ConfigureDefaults(...)`.

There should be a single, clear defaulting path to avoid duplicate configuration/service wiring.

### 📌 Actual behavior

Current flow appears to:
1. Construct `HostApplicationBuilder` (which applies defaults), and
2. Also call `ConfigureDefaults(...)` through the host-builder path.

### ✅ Proposed change

- Audit startup/hosting construction path(s) that use `HostApplicationBuilder`.
- Remove `ConfigureDefaults(...)` invocation on _bootstrapHostBuilder.

### 🧪 Notes

From `dotnet/runtime` behavior:
- `HostApplicationBuilder` constructor applies default config/services directly.
- Calling `ConfigureDefaults()` afterward is generally redundant and will introduce duplicate setup.

### 📚 Environment

- Version: Microsoft.Azure.Functions.Worker 2.51.0
- Repo: `Azure/azure-functions-dotnet-worker`
- Related upstream behavior: `dotnet/runtime` `HostApplicationBuilder`
- Date observed: 2026-03-02

### Steps to reproduce

1. clone this minimal reproduction repo: https://github.com/sinapy/SampleAzureWorkerDuplicateConfiguration
2. Set a breakpoint after the `var configurationSources = builder.Configuration.Sources;` line in Program.cs
3. See how the configuration sources for appsettings.Development.json and appsettings.json is duplicated

Image

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at the FunctionsApplication.CreateBuilder(args) startup path and inspect how HostApplicationBuilder and _bootstrapHostBuilder are constructed and configured. Use the linked minimal reproduction and the breakpoint in Program.cs to verify the configuration sources; done means appsettings.json and appsettings.{Environment}.json are each registered once and the redundant defaulting path is absent.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, csharp
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.