[BUG] AzureClientServiceCollectionExtensions.AddAzureClients attempts to read from config values before validation has occurred #48584
Labels
Client
This issue points to a problem in the data-plane of the library.
customer-reported
Issues that are reported by GitHub users external to the Azure organization.
Extensions
ASP.NET Core extensions
feature-request
This issue requires a new behavior in the product in order be resolved.
Milestone
Library name and version
Microsoft.Extensions.Azure 1.10.0
Describe the bug
In our application we use the Options pattern for strongly-typed config, with validation:
We then reference it during application startup using the following code:
We then use the
AddAzureClients
method to register azure clients using the config object:However, the lambda that is passed as the
Action<AzureClientFactoryBuilder> configureClients
parameter is immediately invoked, and so if e.g.config.BlobStorageUrl
is null, aArgumentNullException
will be thrown. I would normally expect this to occur after validation has happened, so that we would instead get a validation failure that the required config key is missing or invalid.Expected behavior
Normally, when injecting clients, the
configure
action is not invoked until after theStartupValidator
has run and successfully validated the config options. This is the case when normally injecting services, e.g.In that case, if a required config value were missing, we would see e.g.
Actual behavior
On startup, an
ArgumentNullException
is thrown without reference to the specific config value that is missing:Reproduction Steps
Abbreviated Program.cs:
appsettings.json:
Environment
Microsoft Visual Studio Enterprise 2022 (64-bit) - Current
Version 17.11.6
The text was updated successfully, but these errors were encountered: