{"record":{"id":"f7b8585ea5585e50","repo":"MassTransit/MassTransit","slug":"values","errorCode":null,"errorMessage":"values","messagePattern":"values","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/MassTransit.Abstractions/Contexts/Context/PublishEndpointConverterCache.cs","lineNumber":109,"sourceCode":"                if (endpoint == null)\n                    throw new ArgumentNullException(nameof(endpoint));\n                if (message == null)\n                    throw new ArgumentNullException(nameof(message));\n                if (pipe == null)\n                    throw new ArgumentNullException(nameof(pipe));\n\n                if (message is T msg)\n                    return endpoint.Publish(msg, pipe, cancellationToken);\n\n                throw new ArgumentException(\"Unexpected message type: \" + TypeCache.GetShortName(message.GetType()));\n            }\n\n            public Task PublishInitializer(IPublishEndpoint endpoint, object values, CancellationToken cancellationToken)\n            {\n                if (endpoint == null)\n                    throw new ArgumentNullException(nameof(endpoint));\n                if (values == null)\n                    throw new ArgumentNullException(nameof(values));\n\n                return endpoint.Publish<T>(values, cancellationToken);\n            }\n\n            public Task PublishInitializer(IPublishEndpoint endpoint, object values, IPipe<PublishContext> pipe, CancellationToken cancellationToken)\n            {\n                if (endpoint == null)\n                    throw new ArgumentNullException(nameof(endpoint));\n                if (values == null)\n                    throw new ArgumentNullException(nameof(values));\n                if (pipe == null)\n                    throw new ArgumentNullException(nameof(pipe));\n\n                return endpoint.Publish<T>(values, pipe, cancellationToken);\n            }\n        }\n\n","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/MassTransit/MassTransit/blob/62ab339afa3bac2e9b3fe1769d0d35d7e44778e9/src/MassTransit.Abstractions/Contexts/Context/PublishEndpointConverterCache.cs#L91-L127","documentation":"PublishInitializer requires a non-null initializer object (the anonymous object/dictionary whose properties initialize message T); when values is null it throws ArgumentNullException(\"values\"). A null initializer cannot produce a message instance.","triggerScenarios":"Calling the initializer-based publish with values == null, e.g. an anonymous object expression that evaluated to null or a dictionary that was never built.","commonSituations":"Passing the result of a failed mapping; a variable typed object holding null from deserialization; refactor that removed the anonymous-object construction.","solutions":["Ensure a concrete initializer is passed, e.g. publishEndpoint.Publish<OrderSubmitted>(new { OrderId = ... }).","Null-check values before calling and handle the empty case.","Fix upstream mapping so the initializer is always constructed.","If no data is needed, publish a fully constructed message type instead of a null initializer."],"exampleFix":"// before\nobject values = BuildInitializer(); // returns null\nawait publishEndpoint.PublishInitializer(publishEndpoint, values);\n// after\nvar values = new { OrderId = id };\nawait publishEndpoint.Publish<OrderSubmitted>(values);","handlingStrategy":"validation","validationCode":"if (values is null)\n    throw new ArgumentNullException(nameof(values), \"Initializer object must not be null.\");","typeGuard":"bool HasInitializer(object? v) => v is not null;","tryCatchPattern":"try\n{\n    await publishEndpoint.PublishInitializer(publishEndpoint, values, cancellationToken);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"values\")\n{\n    logger.LogError(ex, \"Null initializer passed to PublishInitializer\");\n}","preventionTips":["Always pass an anonymous object or non-null dictionary","Check mappings that feed the initializer for null results","Use nullable reference types to catch null initializer variables","Publish a concrete message instance when there is no data"],"tags":["masstransit","publish","argumentnull","initializer"],"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"}