{"record":{"id":"daf29f56d29a2bf1","repo":"microsoft/aspire","slug":"object-value-cannot-be-null-argumentnullexception-configure-daf29f","errorCode":null,"errorMessage":"Object value cannot be null (ArgumentNullException: configure)","messagePattern":"Object value cannot be null \\(ArgumentNullException: configure\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.AppService/AzureAppServiceWebsiteSlotCustomizationAnnotation.cs","lineNumber":19,"sourceCode":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n\nusing Aspire.Hosting.ApplicationModel;\nusing Azure.Provisioning.AppService;\n\nnamespace Aspire.Hosting.Azure;\n\n/// <summary>\n/// Represents an annotation for customizing an Azure Web App slot.\n/// </summary>\n/// <param name=\"configure\">The configuration action for customizing the Azure Web App slot.</param>\npublic sealed class AzureAppServiceWebsiteSlotCustomizationAnnotation(Action<AzureResourceInfrastructure, WebSiteSlot> configure)\n    : IResourceAnnotation\n{\n    /// <summary>\n    /// Gets the configuration action for customizing the Azure Web App slot.\n    /// </summary>\n    public Action<AzureResourceInfrastructure, WebSiteSlot> Configure { get; } = configure ?? throw new ArgumentNullException(nameof(configure));\n}\n","sourceCodeStart":1,"sourceCodeEnd":21,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.AppService/AzureAppServiceWebsiteSlotCustomizationAnnotation.cs#L1-L21","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Supply a non-null Action<AzureResourceInfrastructure, WebSiteSlot> delegate.","Guard the construction site: only add the annotation when a customization callback is available.","Fix the factory or DI registration that produced the null callback."],"exampleFix":"// before\nvar customize = maybeGetSlotCustomizer(); // may be null\nresource.WithAnnotation(new AzureAppServiceWebsiteSlotCustomizationAnnotation(customize!));\n// after\nif (customize is not null)\n{\n    resource.WithAnnotation(new AzureAppServiceWebsiteSlotCustomizationAnnotation(customize));\n}","handlingStrategy":"validation","validationCode":"if (configure is null)\n    throw new ArgumentNullException(nameof(configure), \"Provide a slot customization action before creating AzureAppServiceWebsiteSlotCustomizationAnnotation.\");\nresource.WithAnnotation(new AzureAppServiceWebsiteSlotCustomizationAnnotation(configure));","typeGuard":"if (configure is not null)\n    resource.WithAnnotation(new AzureAppServiceWebsiteSlotCustomizationAnnotation(configure));","tryCatchPattern":"try { resource.WithAnnotation(new AzureAppServiceWebsiteSlotCustomizationAnnotation(configure)); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"configure\")\n{\n    logger.LogError(ex, \"Slot customization callback was null; skipping annotation.\");\n}","preventionTips":["Construct slot annotations with inline lambdas to avoid null delegate paths.","Gate annotation registration on the callback being non-null.","Cover slot customization setup with a unit test that constructs the annotation to fail fast on regressions."],"tags":["azure-app-service","null-argument","annotation","deployment-slots","constructor"],"backgroundTag":"null-argument","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}