{"record":{"id":"f64fffdc063c8145","repo":"MassTransit/MassTransit","slug":"connector","errorCode":null,"errorMessage":"connector","messagePattern":"connector","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/MassTransit/Configuration/AuditConfigurationExtensions.cs","lineNumber":46,"sourceCode":"\n            var sendHandle = connector.ConnectSendObserver(new AuditSendObserver(store, factory, specification.Filter));\n            var publishHandle = connector.ConnectPublishObserver(new AuditPublishObserver(store, factory, specification.Filter));\n\n            return new MultipleConnectHandle(sendHandle, publishHandle);\n        }\n\n        /// <summary>\n        /// Add an observer that will audit consumed messages, sending them to the message audit store prior to consumption by the consumer\n        /// </summary>\n        /// <param name=\"connector\">The bus or endpoint</param>\n        /// <param name=\"store\">The audit store</param>\n        /// <param name=\"configureFilter\">Filter configuration delegate</param>\n        /// <param name=\"metadataFactory\">Message metadata factory. If omitted, the default one will be used.</param>\n        public static ConnectHandle ConnectConsumeAuditObserver(this IConsumeObserverConnector connector, IMessageAuditStore store,\n            Action<IMessageFilterConfigurator> configureFilter = null, IConsumeMetadataFactory metadataFactory = null)\n        {\n            if (connector == null)\n                throw new ArgumentNullException(nameof(connector));\n            if (store == null)\n                throw new ArgumentNullException(nameof(store));\n\n            var filterConfigurator = new ConsumeMessageFilterConfigurator();\n            configureFilter?.Invoke(filterConfigurator);\n\n            var factory = metadataFactory ?? new DefaultConsumeMetadataFactory();\n\n            return connector.ConnectConsumeObserver(new AuditConsumeObserver(store, factory, filterConfigurator.Filter));\n        }\n    }\n}\n","sourceCodeStart":28,"sourceCodeEnd":59,"githubUrl":"https://github.com/MassTransit/MassTransit/blob/62ab339afa3bac2e9b3fe1769d0d35d7e44778e9/src/MassTransit/Configuration/AuditConfigurationExtensions.cs#L28-L59","documentation":"The ConnectConsumeAuditObserver extension throws ArgumentNullException (parameter 'connector') when the IConsumeObserverConnector it is called on is null. The connector is the receiver of the audit observer, so it must be a live bus/massTransit instance.","triggerScenarios":"Invoking the extension on a null bus or null IBus instance, e.g. bus = await Bus.Factory... failing earlier or a field never initialized, then calling bus.ConnectConsumeAuditObserver(...).","commonSituations":"Audit wiring run before the bus is started/created; DI returning a null IBus; calling the extension on a stale disposed bus variable.","solutions":["Ensure the bus is created and started before connecting the audit observer","Null-check the bus instance before wiring auditing","Resolve IBus from the DI container after host startup rather than a cached field"],"exampleFix":"// before\n_bus.ConnectConsumeAuditObserver(store); // _bus may be null\n// after\nif (_bus == null) throw new InvalidOperationException(\"bus not started\");\n_bus.ConnectConsumeAuditObserver(store);","handlingStrategy":"validation","validationCode":"if (bus is null) throw new InvalidOperationException(\"bus must be started before connecting the audit observer\");","typeGuard":"bool CanAudit(IBus? bus) => bus is not null;","tryCatchPattern":"try { bus.ConnectConsumeAuditObserver(store); } catch (ArgumentNullException ex) { logger.LogError(ex, \"null connector for audit observer\"); throw; }","preventionTips":["Wire auditing after the bus is built and started","Resolve IBus via DI instead of cached fields","Null-check the bus in startup code"],"tags":["null-check","auditing","argumentnull"],"backgroundTag":"null-argument","analyzedSha":"62ab339afa3bac2e9b3fe1769d0d35d7e44778e9","analyzedAt":"2026-09-13T22:47:47.593Z","contentChangedAt":"2026-09-13T22:47:47.593Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}