{"record":{"id":"133f5fec64601d18","repo":"dotnetcore/CAP","slug":"addcap-must-be-added-on-the-service-collection-eg-services","errorCode":null,"errorMessage":"AddCap() must be added on the service collection.   eg: services.AddCap(...)","messagePattern":"AddCap\\(\\) must be added on the service collection\\.   eg: services\\.AddCap\\(\\.\\.\\.\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/DotNetCore.CAP/Internal/IBootstrapper.Default.cs","lineNumber":131,"sourceCode":"    }\n\n    protected override async Task ExecuteAsync(CancellationToken stoppingToken)\n    {\n        await BootstrapAsync(stoppingToken).ConfigureAwait(false);\n    }\n\n    public override async Task StopAsync(CancellationToken cancellationToken)\n    {\n        _cts?.Cancel();\n\n        await base.StopAsync(cancellationToken).ConfigureAwait(false);\n    }\n\n    private void CheckRequirement()\n    {\n        var marker = _serviceProvider.GetService<CapMarkerService>();\n        if (marker == null)\n            throw new InvalidOperationException(\n                \"AddCap() must be added on the service collection.   eg: services.AddCap(...)\");\n\n        var messageQueueMarker = _serviceProvider.GetService<CapMessageQueueMakerService>();\n        if (messageQueueMarker == null)\n            throw new InvalidOperationException(\n                \"You must be config transport provider for CAP!\" + Environment.NewLine +\n                \"==================================================================================\" +\n                Environment.NewLine +\n                \"========   eg: services.AddCap( options => { options.UseRabbitMQ(...) }); ========\" +\n                Environment.NewLine +\n                \"==================================================================================\");\n\n        var databaseMarker = _serviceProvider.GetService<CapStorageMarkerService>();\n        if (databaseMarker == null)\n            throw new InvalidOperationException(\n                \"You must be config storage provider for CAP!\" + Environment.NewLine +\n                \"===================================================================================\" +\n                Environment.NewLine +","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/dotnetcore/CAP/blob/e52b8508e54cdb7a9ce7f9fec03d9ea8ad2710fb/src/DotNetCore.CAP/Internal/IBootstrapper.Default.cs#L113-L149","documentation":"A bootstrap-time configuration guard in CheckRequirement: the CapMarkerService is not present in DI, which proves services.AddCAP(...) was never called before the CAP bootstrapper started. It fires during application startup (from BootstrapAsync), not during message processing, and simply means CAP was never registered on the service collection.","triggerScenarios":"Thrown at src/DotNetCore.CAP/Internal/IBootstrapper.Default.cs:131 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Call services.AddCAP(options => ...) on your IServiceCollection during startup (Program.cs or Startup.ConfigureServices).","If using a partitioned/layered registration, make sure the AddCAP call executes in the same service collection used to build the final IServiceProvider."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e52b8508e54cdb7a9ce7f9fec03d9ea8ad2710fb","analyzedAt":"2026-09-14T14:46:34.677Z","contentChangedAt":"2026-09-14T14:46:34.677Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}