microsoft/aspire · error · ArgumentNullException

Value cannot be null. (Parameter 'resourceLoggerService')

Error message

Value cannot be null. (Parameter 'resourceLoggerService')

What it means

The current ResourceNotificationService constructor validates its ResourceLoggerService parameter and throws ArgumentNullException when null. Both the notification service and logger service must come from the same host DI wiring.

Solutions

  1. Create a ResourceLoggerService instance and pass it (new ResourceLoggerService())
  2. Resolve ResourceLoggerService from the host's DI container
  3. Construct the whole service via DI (host.RunAsync wiring) rather than manually

Example fix

// before
new ResourceNotificationService(logger, lifetime, sp, null);
// after
new ResourceNotificationService(logger, lifetime, sp, new ResourceLoggerService());
Defensive patterns

Strategy: validation

Validate before calling

ArgumentNullException.ThrowIfNull(resourceLoggerService); // before constructing

Try / catch

try { var svc = new ResourceNotificationService(logger, lifetime, sp, rls); }
catch (ArgumentNullException) { /* construct a ResourceLoggerService and retry */ }

Prevention

When it happens

Trigger: Calling new ResourceNotificationService(logger, lifetime, serviceProvider, null) — e.g., forgetting to construct or resolve ResourceLoggerService in test scaffolding.

Common situations: Manual service construction in tests; partial DI setup where ResourceLoggerService was not registered with AddResourceLoggerService-style host wiring.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/7a1c6c44b3a13dc8. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Hosting/ApplicationModel/ResourceNotificationService.cs:76

        DefaultWaitBehavior = WaitBehavior.StopOnResourceUnavailable;
    }

    /// <summary>
    /// Creates a new instance of <see cref="ResourceNotificationService"/>.
    /// </summary>
    /// <param name="logger">The logger.</param>
    /// <param name="hostApplicationLifetime">The host application lifetime.</param>
    /// <param name="resourceLoggerService">The resource logger service.</param>
    /// <param name="serviceProvider">The service provider.</param>
    public ResourceNotificationService(
        ILogger<ResourceNotificationService> logger,
        IHostApplicationLifetime hostApplicationLifetime,
        IServiceProvider serviceProvider,
        ResourceLoggerService resourceLoggerService)
    {
        _logger = logger ?? throw new ArgumentNullException(nameof(logger));
        _serviceProvider = serviceProvider;
        _resourceLoggerService = resourceLoggerService ?? throw new ArgumentNullException(nameof(resourceLoggerService));
        DefaultWaitBehavior = serviceProvider.GetService<IOptions<ResourceNotificationServiceOptions>>()?.Value.DefaultWaitBehavior ?? WaitBehavior.StopOnResourceUnavailable;

        // The IHostApplicationLifetime parameter is not used anymore, but we keep it for backwards compatibility.
        // Notification updates will be cancelled when the service is disposed.
    }

    private class NullServiceProvider : IServiceProvider
    {
        public object? GetService(Type serviceType) => null;
    }

    /// <summary>
    /// Waits for a resource to reach the specified state. See <see cref="KnownResourceStates"/> for common states.
    /// </summary>
    /// <remarks>
    /// This method returns a task that will complete when the resource reaches the specified target state. If the resource
    /// is already in the target state, the method will return immediately.<br/>
    /// If the resource doesn't reach one of the target states before <paramref name="cancellationToken"/> is signaled, this method

View on GitHub (pinned to 25830f84bd)