microsoft/aspire · error · ArgumentNullException

Object value cannot be null (ArgumentNullException…

Error message

Object value cannot be null (ArgumentNullException: configure)

What it means

AzureAppServiceWebsiteSlotCustomizationAnnotation stores a delegate invoked when the WebSiteSlot bicep resource is built during publish. Its constructor null-checks the delegate and throws ArgumentNullException ('configure') when null is supplied, surfacing the mistake at annotation creation time.

Solutions

  1. Supply a non-null Action<AzureResourceInfrastructure, WebSiteSlot> delegate.
  2. Guard the construction site: only add the annotation when a customization callback is available.
  3. Fix the factory or DI registration that produced the null callback.

Example fix

// before
var customize = maybeGetSlotCustomizer(); // may be null
resource.WithAnnotation(new AzureAppServiceWebsiteSlotCustomizationAnnotation(customize!));
// after
if (customize is not null)
{
    resource.WithAnnotation(new AzureAppServiceWebsiteSlotCustomizationAnnotation(customize));
}
Defensive patterns

Strategy: validation

Validate before calling

if (configure is null)
    throw new ArgumentNullException(nameof(configure), "Provide a slot customization action before creating AzureAppServiceWebsiteSlotCustomizationAnnotation.");
resource.WithAnnotation(new AzureAppServiceWebsiteSlotCustomizationAnnotation(configure));

Type guard

if (configure is not null)
    resource.WithAnnotation(new AzureAppServiceWebsiteSlotCustomizationAnnotation(configure));

Try / catch

try { resource.WithAnnotation(new AzureAppServiceWebsiteSlotCustomizationAnnotation(configure)); }
catch (ArgumentNullException ex) when (ex.ParamName == "configure")
{
    logger.LogError(ex, "Slot customization callback was null; skipping annotation.");
}

Prevention

When it happens

Trigger: Constructing the annotation with a null Action<AzureResourceInfrastructure, WebSiteSlot> — e.g. passing an unassigned lambda variable, a null return from a factory, or using WithAnnotation with a default-constructed instance.

Common situations: Deployment-slot customization code where the callback is conditionally built (and ends up null); reflection-driven annotation registration; copy-paste from a method returning null on some paths.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/daf29f56d29a2bf1. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Hosting.Azure.AppService/AzureAppServiceWebsiteSlotCustomizationAnnotation.cs:19

// 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 slot.
/// </summary>
/// <param name="configure">The configuration action for customizing the Azure Web App slot.</param>
public sealed class AzureAppServiceWebsiteSlotCustomizationAnnotation(Action<AzureResourceInfrastructure, WebSiteSlot> configure)
    : IResourceAnnotation
{
    /// <summary>
    /// Gets the configuration action for customizing the Azure Web App slot.
    /// </summary>
    public Action<AzureResourceInfrastructure, WebSiteSlot> Configure { get; } = configure ?? throw new ArgumentNullException(nameof(configure));
}

View on GitHub (pinned to 25830f84bd)