{"record":{"id":"b0dbe1789a72da83","repo":"microsoft/autogen","slug":"cloudevent-is-null","errorCode":null,"errorMessage":"CloudEvent is null.","messagePattern":"CloudEvent is null\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Microsoft.AutoGen/Core.Grpc/GrpcAgentRuntime.cs","lineNumber":218,"sourceCode":"        }\n        if (request.RequestId is null)\n        {\n            throw new InvalidOperationException(\"RequestId is null.\");\n        }\n\n        if (_pendingRequests.TryRemove(request.RequestId, out var resultSink))\n        {\n            var payload = request.Payload;\n            var message = payload.ToObject(SerializationRegistry);\n            resultSink.SetResult(message);\n        }\n    }\n\n    private async ValueTask HandlePublish(CloudEvent evt, CancellationToken cancellationToken = default)\n    {\n        if (evt is null)\n        {\n            throw new InvalidOperationException(\"CloudEvent is null.\");\n        }\n        if (evt.ProtoData is null)\n        {\n            throw new InvalidOperationException(\"ProtoData is null.\");\n        }\n        if (evt.Attributes is null)\n        {\n            throw new InvalidOperationException(\"Attributes is null.\");\n        }\n\n        var topic = new TopicId(evt.Type, evt.Source);\n        Contracts.AgentId? sender = null;\n        if (evt.Attributes.TryGetValue(Constants.AGENT_SENDER_TYPE_ATTR, out var typeValue) && evt.Attributes.TryGetValue(Constants.AGENT_SENDER_KEY_ATTR, out var keyValue))\n        {\n            sender = new Contracts.AgentId\n            {\n                Type = typeValue.CeString,\n                Key = keyValue.CeString","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/Microsoft.AutoGen/Core.Grpc/GrpcAgentRuntime.cs#L200-L236","documentation":"GrpcAgentRuntime.HandlePublish throws InvalidOperationException when an incoming CloudEvent is null. Published messages arrive as CloudEvent envelopes over the gRPC stream; a null envelope fails the handler's defensive validation before topic/sender extraction (TopicId, Attributes) begins.","triggerScenarios":"The message router delivers a null CloudEvent to HandlePublish — malformed stream data, incompatible proto versions between publisher and runtime, or direct internal invocation with null (custom sinks/tests).","commonSituations":"Version skew of the AgentRpc/CloudEvent contract between processes; a custom IMessageSink<Message> implementation forwarding null; test harnesses exercising HandlePublish directly.","solutions":["Pin matching Microsoft.AutoGen package versions across all publishing and subscribing processes.","Check custom message-sink/router glue for paths that can forward a null event.","In tests, construct a CloudEvent with Type, Source, ProtoData, and Attributes set."],"exampleFix":"// before (test double)\nawait runtime.HandlePublish(null); // throws\n\n// after\nvar evt = new CloudEvent\n{\n    Type = topic.Type,\n    Source = topic.Source,\n    ProtoData = message.ToProtobuf(registry),\n    Attributes = { /* ... */ },\n};\nawait runtime.HandlePublish(evt);","handlingStrategy":"validation","validationCode":"if (cloudEvent is null) { /* drop/log the malformed frame; verify proto version alignment */ }","typeGuard":"static bool IsValidCloudEvent(CloudEvent? e) => e is not null && e.ProtoData is not null && e.Attributes is not null;","tryCatchPattern":"try { await runtime.HandlePublish(evt); }\ncatch (InvalidOperationException) { /* log envelope; check contract/version alignment */ }","preventionTips":["Pin identical Microsoft.AutoGen versions across publishers and subscribers.","Guard custom message-sink implementations against forwarding null events, with a log + counter."],"tags":["grpc","wire-protocol","cloud-events","pubsub"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}