microsoft/aspire · error · ArgumentNullException
ArgumentNullException for parameter 'callback' (callback is…
Error message
ArgumentNullException for parameter 'callback' (callback is null).
What it means
CertificateTrustConfigurationCallbackAnnotation wraps a callback that customizes certificate trust for a resource. The constructor requires a non-null callback; passing null throws ArgumentNullException for parameter 'callback'.
Solutions
- Pass a valid async callback, e.g. ctx => { ...; return Task.CompletedTask; }
- If the annotation is conditional, only add it when the callback delegate is available
- Null-check the delegate at the call site before constructing the annotation
Example fix
// before
resource.Annotations.Add(new CertificateTrustConfigurationCallbackAnnotation(null));
// after
resource.Annotations.Add(new CertificateTrustConfigurationCallbackAnnotation(context =>
{
context.CertificateTrustConfiguration... // customize trust
return Task.CompletedTask;
})); Defensive patterns
Strategy: validation
Validate before calling
if (callback is null) throw new InvalidOperationException("Certificate trust callback must be configured before adding the annotation."); Try / catch
try { ann = new CertificateTrustConfigurationCallbackAnnotation(callback); } catch (ArgumentNullException) { ann = new CertificateTrustConfigurationCallbackAnnotation(DefaultTrustCallback); } Prevention
- Pass lambda callbacks inline rather than nullable delegate variables
- Only add the annotation when the callback is available
- Null-check delegates sourced from DI or options
When it happens
Trigger: new CertificateTrustConfigurationCallbackAnnotation(null) or passing a variable/chain that resolves to null (e.g. a conditional expression yielding null, or a method returning a null Func).
Common situations: Building annotations dynamically where the callback delegate was never assigned; refactoring removed the lambda but left the annotation; dependency injection failed to supply the delegate.
Related errors
- ArgumentNullException for parameter 'resource' (resource is…
- description
- Object must be initialized before it can be used
- Object value cannot be null (ArgumentNullException…
- Object value cannot be null (ArgumentNullException…
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/2990d7c4d7b4e5f8.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting/ApplicationModel/CertificateTrustConfigurationCallbackAnnotation.cs:18
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Diagnostics.CodeAnalysis;
using System.Security.Cryptography.X509Certificates;
namespace Aspire.Hosting.ApplicationModel;
/// <summary>
/// An annotation that indicates a resource wants to manage how custom certificate trust is configured.
/// </summary>
/// <param name="callback">The callback used to customize certificate trust for the resource.</param>
public sealed class CertificateTrustConfigurationCallbackAnnotation(Func<CertificateTrustConfigurationCallbackAnnotationContext, Task> callback) : IResourceAnnotation
{
/// <summary>
/// Gets the callback to invoke to populate or modify the certificate authority collection.
/// </summary>
public Func<CertificateTrustConfigurationCallbackAnnotationContext, Task> Callback { get; } = callback ?? throw new ArgumentNullException(nameof(callback));
}
/// <summary>
/// Context provided to a <see cref="CertificateTrustConfigurationCallbackAnnotation"/> callback.
/// </summary>
public sealed class CertificateTrustConfigurationCallbackAnnotationContext
{
/// <summary>
/// Gets the <see cref="DistributedApplicationExecutionContext"/> for this session.
/// </summary>
public required DistributedApplicationExecutionContext ExecutionContext { get; init; }
/// <summary>
/// Gets the resource to which the annotation is applied.
/// </summary>
public required IResource Resource { get; init; }
/// <summary>View on GitHub (pinned to 25830f84bd)