microsoft/aspire · error · ArgumentNullException
Object value cannot be null (ArgumentNullException…
Error message
Object value cannot be null (ArgumentNullException: configure)
What it means
The AzureAppServiceWebsiteCustomizationAnnotation constructor wraps a delegate invoked when the WebSite bicep resource is built. It immediately null-checks the delegate and throws ArgumentNullException ('configure') when null is passed, so bad usage fails at annotation construction rather than deep in publishing.
Solutions
- Provide a non-null Action<AzureResourceInfrastructure, WebSite> when creating the annotation.
- Check for null before constructing/adding the annotation, or skip adding it when no customization is needed.
- Fix factory/dependency-injection code so the callback resolves to a real method group or lambda.
Example fix
// before
resource.WithAnnotation(new AzureAppServiceWebsiteCustomizationAnnotation(null!));
// after
resource.WithAnnotation(new AzureAppServiceWebsiteCustomizationAnnotation((infra, site) =>
{
site.Tags.Add("env", "prod");
})); Defensive patterns
Strategy: validation
Validate before calling
if (configure is null)
throw new ArgumentNullException(nameof(configure), "Provide a customization action before creating AzureAppServiceWebsiteCustomizationAnnotation.");
resource.WithAnnotation(new AzureAppServiceWebsiteCustomizationAnnotation(configure)); Type guard
if (configure is not null)
resource.WithAnnotation(new AzureAppServiceWebsiteCustomizationAnnotation(configure)); Try / catch
try { resource.WithAnnotation(new AzureAppServiceWebsiteCustomizationAnnotation(configure)); }
catch (ArgumentNullException ex) when (ex.ParamName == "configure")
{
logger.LogError(ex, "Website customization callback was null; skipping annotation.");
} Prevention
- Never pass null delegates to annotation constructors; use lambdas inline.
- Null-check callbacks obtained from factories or configuration before adding the annotation.
- Favor skipping the annotation entirely over adding one with a no-op or null callback.
When it happens
Trigger: Passing null as the configure delegate, e.g. calling WithAnnotation<AzureAppServiceWebsiteCustomizationAnnotation>(default) or constructing the annotation via a factory/reflection path that supplies a null Action<AzureResourceInfrastructure, WebSite>.
Common situations: Conditional callback selection where a local variable is null; generic annotation-adding helpers that pass through null; typos invoking the wrong overload or a variable that was never assigned.
Related errors
- Object value cannot be null (ArgumentNullException…
- ArgumentNullException for parameter 'callback' (callback is…
- ArgumentNullException for parameter 'resource' (resource is…
- description
- Object must be initialized before it can be used
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/0ee33b67d75e1539.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Azure.AppService/AzureAppServiceWebsiteCustomizationAnnotation.cs:18
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Aspire.Hosting.ApplicationModel;
using Azure.Provisioning.AppService;
namespace Aspire.Hosting.Azure;
/// <summary>
/// Represents an annotation for customizing an Azure Web App.
/// </summary>
public sealed class AzureAppServiceWebsiteCustomizationAnnotation(Action<AzureResourceInfrastructure, WebSite> configure)
: IResourceAnnotation
{
/// <summary>
/// Gets the configuration action for customizing the Azure Web App.
/// </summary>
public Action<AzureResourceInfrastructure, WebSite> Configure { get; } = configure ?? throw new ArgumentNullException(nameof(configure));
}
View on GitHub (pinned to 25830f84bd)