{"record":{"id":"9c6b023659a1bbd7","repo":"microsoft/aspire","slug":"value-cannot-be-null-parameter-resource","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'resource')","messagePattern":"Value cannot be null\\. \\(Parameter 'resource'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.FrontDoor/AzureFrontDoorOriginAnnotation.cs","lineNumber":16,"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;\n\nnamespace Aspire.Hosting.Azure;\n\n/// <summary>\n/// Represents an origin to be added to an Azure Front Door resource.\n/// </summary>\ninternal sealed class AzureFrontDoorOriginAnnotation(IResourceWithEndpoints resource) : IResourceAnnotation\n{\n    /// <summary>\n    /// Gets the resource for this origin.\n    /// </summary>\n    public IResourceWithEndpoints Resource { get; } = resource ?? throw new ArgumentNullException(nameof(resource));\n}\n","sourceCodeStart":1,"sourceCodeEnd":18,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.FrontDoor/AzureFrontDoorOriginAnnotation.cs#L1-L18","documentation":"AzureFrontDoorOriginAnnotation stores the resource that acts as a Front Door origin and its constructor guards against null with a standard ArgumentNullException throw-expression. This fails fast when internal code (or user code via reflection/extension APIs) constructs the annotation without a resource.","triggerScenarios":"Constructing new AzureFrontDoorOriginAnnotation(null) directly, or calling an internal helper that forwards a null resource (e.g., a generic origin API that failed to resolve an IResourceWithEndpoints).","commonSituations":"Writing custom Front Door extension methods that pass a possibly-null resource into the annotation; test code building annotations manually; a builder API returning null for the target resource.","solutions":["Pass a valid IResourceWithEndpoints instance when creating the annotation; resolve the resource from the builder before constructing it.","Null-check the resource at the call site and surface a clearer error before constructing the annotation.","Update custom extension code to use WithReference-style APIs instead of constructing annotations directly."],"exampleFix":"// before\nvar annotation = new AzureFrontDoorOriginAnnotation(resource!); // resource may be null\n\n// after\nif (resource is null)\n{\n    throw new InvalidOperationException(\"Origin resource was not resolved.\");\n}\nvar annotation = new AzureFrontDoorOriginAnnotation(resource);","handlingStrategy":"type-guard","validationCode":"if (resource is null) throw new InvalidOperationException(\"Origin resource must be resolved before creating AzureFrontDoorOriginAnnotation.\");","typeGuard":"static bool IsValidOriginResource(object? r) => r is IResourceWithEndpoints;","tryCatchPattern":"try { var ann = new AzureFrontDoorOriginAnnotation(resource); } catch (ArgumentNullException ex) when (ex.ParamName == \"resource\") { /* resolve resource from builder first */ }","preventionTips":["Never construct resource annotations directly; use builder extension APIs.","Null-check builder.Resource before annotation construction.","Use nullable reference types so NRT warnings surface null resources early."],"tags":["aspire","azure-frontdoor","null-argument","annotation"],"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"}