{"record":{"id":"7a1c6c44b3a13dc8","repo":"microsoft/aspire","slug":"value-cannot-be-null-parameter-resourceloggerservice","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'resourceLoggerService')","messagePattern":"Value cannot be null\\. \\(Parameter 'resourceLoggerService'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting/ApplicationModel/ResourceNotificationService.cs","lineNumber":76,"sourceCode":"        DefaultWaitBehavior = WaitBehavior.StopOnResourceUnavailable;\n    }\n\n    /// <summary>\n    /// Creates a new instance of <see cref=\"ResourceNotificationService\"/>.\n    /// </summary>\n    /// <param name=\"logger\">The logger.</param>\n    /// <param name=\"hostApplicationLifetime\">The host application lifetime.</param>\n    /// <param name=\"resourceLoggerService\">The resource logger service.</param>\n    /// <param name=\"serviceProvider\">The service provider.</param>\n    public ResourceNotificationService(\n        ILogger<ResourceNotificationService> logger,\n        IHostApplicationLifetime hostApplicationLifetime,\n        IServiceProvider serviceProvider,\n        ResourceLoggerService resourceLoggerService)\n    {\n        _logger = logger ?? throw new ArgumentNullException(nameof(logger));\n        _serviceProvider = serviceProvider;\n        _resourceLoggerService = resourceLoggerService ?? throw new ArgumentNullException(nameof(resourceLoggerService));\n        DefaultWaitBehavior = serviceProvider.GetService<IOptions<ResourceNotificationServiceOptions>>()?.Value.DefaultWaitBehavior ?? WaitBehavior.StopOnResourceUnavailable;\n\n        // The IHostApplicationLifetime parameter is not used anymore, but we keep it for backwards compatibility.\n        // Notification updates will be cancelled when the service is disposed.\n    }\n\n    private class NullServiceProvider : IServiceProvider\n    {\n        public object? GetService(Type serviceType) => null;\n    }\n\n    /// <summary>\n    /// Waits for a resource to reach the specified state. See <see cref=\"KnownResourceStates\"/> for common states.\n    /// </summary>\n    /// <remarks>\n    /// This method returns a task that will complete when the resource reaches the specified target state. If the resource\n    /// is already in the target state, the method will return immediately.<br/>\n    /// If the resource doesn't reach one of the target states before <paramref name=\"cancellationToken\"/> is signaled, this method","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/ApplicationModel/ResourceNotificationService.cs#L58-L94","documentation":"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.","triggerScenarios":"Calling new ResourceNotificationService(logger, lifetime, serviceProvider, null) — e.g., forgetting to construct or resolve ResourceLoggerService in test scaffolding.","commonSituations":"Manual service construction in tests; partial DI setup where ResourceLoggerService was not registered with AddResourceLoggerService-style host wiring.","solutions":["Create a ResourceLoggerService instance and pass it (new ResourceLoggerService())","Resolve ResourceLoggerService from the host's DI container","Construct the whole service via DI (host.RunAsync wiring) rather than manually"],"exampleFix":"// before\nnew ResourceNotificationService(logger, lifetime, sp, null);\n// after\nnew ResourceNotificationService(logger, lifetime, sp, new ResourceLoggerService());","handlingStrategy":"validation","validationCode":"ArgumentNullException.ThrowIfNull(resourceLoggerService); // before constructing","typeGuard":null,"tryCatchPattern":"try { var svc = new ResourceNotificationService(logger, lifetime, sp, rls); }\ncatch (ArgumentNullException) { /* construct a ResourceLoggerService and retry */ }","preventionTips":["Construct notification and logger services together from the same DI container","In tests, create new ResourceLoggerService() alongside the notification service"],"tags":["aspire","null-argument","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"}