microsoft/aspire · error · ArgumentNullException
Value cannot be null. (Parameter 'resource')
Error message
Value cannot be null. (Parameter 'resource')
What it means
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.
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.
Example fix
// before
var annotation = new AzureFrontDoorOriginAnnotation(resource!); // resource may be null
// after
if (resource is null)
{
throw new InvalidOperationException("Origin resource was not resolved.");
}
var annotation = new AzureFrontDoorOriginAnnotation(resource); Defensive patterns
Strategy: type-guard
Validate before calling
if (resource is null) throw new InvalidOperationException("Origin resource must be resolved before creating AzureFrontDoorOriginAnnotation."); Type guard
static bool IsValidOriginResource(object? r) => r is IResourceWithEndpoints;
Try / catch
try { var ann = new AzureFrontDoorOriginAnnotation(resource); } catch (ArgumentNullException ex) when (ex.ParamName == "resource") { /* resolve resource from builder first */ } Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- adminPassword
- ArgumentNullException for parameter 'callback' (callback is…
- ArgumentNullException for parameter 'resource' (resource is…
- Array params contains null item
- description
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/9c6b023659a1bbd7.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Azure.FrontDoor/AzureFrontDoorOriginAnnotation.cs:16
// 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;
namespace Aspire.Hosting.Azure;
/// <summary>
/// Represents an origin to be added to an Azure Front Door resource.
/// </summary>
internal sealed class AzureFrontDoorOriginAnnotation(IResourceWithEndpoints resource) : IResourceAnnotation
{
/// <summary>
/// Gets the resource for this origin.
/// </summary>
public IResourceWithEndpoints Resource { get; } = resource ?? throw new ArgumentNullException(nameof(resource));
}
View on GitHub (pinned to 25830f84bd)