{"record":{"id":"174c065d49ac3229","repo":"microsoft/aspire","slug":"value-cannot-be-null-parameter-logger-174c06","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'logger')","messagePattern":"Value cannot be null\\. \\(Parameter 'logger'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting/ApplicationModel/ResourceNotificationService.cs","lineNumber":55,"sourceCode":"    internal WaitBehavior DefaultWaitBehavior { get; set; }\n\n    /// <summary>\n    /// Creates a new instance of <see cref=\"ResourceNotificationService\"/>.\n    /// </summary>\n    /// <remarks>\n    /// Obsolete. Use the constructor that accepts an <see cref=\"ILogger{ResourceNotificationService}\"/>, <see cref=\"IHostApplicationLifetime\"/> and <see cref=\"IServiceProvider\"/>.<br/>\n    /// This constructor will be removed in the next major version of Aspire.\n    /// </remarks>\n    /// <param name=\"logger\">The logger.</param>\n    /// <param name=\"hostApplicationLifetime\">The host application lifetime.</param>\n    [Obsolete($\"\"\"\n        {nameof(ResourceNotificationService)} now requires an {nameof(IServiceProvider)} and {nameof(ResourceLoggerService)}.\n        Use the constructor that accepts an {nameof(ILogger)}<{nameof(ResourceNotificationService)}>, {nameof(IHostApplicationLifetime)}, {nameof(IServiceProvider)} and {nameof(ResourceLoggerService)}.\n        This constructor will be removed in the next major version of Aspire.\n        \"\"\")]\n    public ResourceNotificationService(ILogger<ResourceNotificationService> logger, IHostApplicationLifetime hostApplicationLifetime)\n    {\n        _logger = logger ?? throw new ArgumentNullException(nameof(logger));\n        _serviceProvider = new NullServiceProvider();\n        _resourceLoggerService = new ResourceLoggerService();\n        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    {","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/ApplicationModel/ResourceNotificationService.cs#L37-L73","documentation":"This obsolete ResourceNotificationService constructor requires a non-null ILogger<ResourceNotificationService>. Passing null fails fast via ArgumentNullException. The constructor exists only for backward compatibility and will be removed.","triggerScenarios":"Calling new ResourceNotificationService(null, hostApplicationLifetime) or passing a null logger from legacy host-building code.","commonSituations":"Migrating old code that previously constructed the service manually; DI containers supplying null due to missing ILogger registrations.","solutions":["Use the 4-parameter constructor (ILogger, IHostApplicationLifetime, IServiceProvider, ResourceLoggerService)","Register ILogger<T> in the DI container or use NullLogger<ResourceNotificationService>.Instance in tests","Remove direct construction and resolve the service from DI"],"exampleFix":"// before\nnew ResourceNotificationService(null, lifetime);\n// after\nnew ResourceNotificationService(NullLogger<ResourceNotificationService>.Instance, lifetime,\n    services, new ResourceLoggerService());","handlingStrategy":"validation","validationCode":"if (logger is null) logger = NullLogger<ResourceNotificationService>.Instance;","typeGuard":null,"tryCatchPattern":"try { var svc = new ResourceNotificationService(logger, lifetime); }\ncatch (ArgumentNullException) { /* supply a logger or migrate to the DI constructor */ }","preventionTips":["Migrate off the obsolete 2-parameter constructor","Use NullLogger<T>.Instance in tests instead of null"],"tags":["aspire","null-argument","obsolete-api"],"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"}