{"record":{"id":"0ee33b67d75e1539","repo":"microsoft/aspire","slug":"object-value-cannot-be-null-argumentnullexception-configure","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/AzureAppServiceWebsiteCustomizationAnnotation.cs","lineNumber":18,"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.\n/// </summary>\npublic sealed class AzureAppServiceWebsiteCustomizationAnnotation(Action<AzureResourceInfrastructure, WebSite> configure)\n    : IResourceAnnotation\n{\n    /// <summary>\n    /// Gets the configuration action for customizing the Azure Web App.\n    /// </summary>\n    public Action<AzureResourceInfrastructure, WebSite> Configure { get; } = configure ?? throw new ArgumentNullException(nameof(configure));\n}\n","sourceCodeStart":1,"sourceCodeEnd":20,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.AppService/AzureAppServiceWebsiteCustomizationAnnotation.cs#L1-L20","documentation":"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.","triggerScenarios":"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>.","commonSituations":"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.","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."],"exampleFix":"// before\nresource.WithAnnotation(new AzureAppServiceWebsiteCustomizationAnnotation(null!));\n// after\nresource.WithAnnotation(new AzureAppServiceWebsiteCustomizationAnnotation((infra, site) =>\n{\n    site.Tags.Add(\"env\", \"prod\");\n}));","handlingStrategy":"validation","validationCode":"if (configure is null)\n    throw new ArgumentNullException(nameof(configure), \"Provide a customization action before creating AzureAppServiceWebsiteCustomizationAnnotation.\");\nresource.WithAnnotation(new AzureAppServiceWebsiteCustomizationAnnotation(configure));","typeGuard":"if (configure is not null)\n    resource.WithAnnotation(new AzureAppServiceWebsiteCustomizationAnnotation(configure));","tryCatchPattern":"try { resource.WithAnnotation(new AzureAppServiceWebsiteCustomizationAnnotation(configure)); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"configure\")\n{\n    logger.LogError(ex, \"Website customization callback was null; skipping annotation.\");\n}","preventionTips":["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."],"tags":["azure-app-service","null-argument","annotation","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"}