{"record":{"id":"b14e14037b6f4979","repo":"microsoft/autogen","slug":"attributes-is-null","errorCode":null,"errorMessage":"Attributes is null.","messagePattern":"Attributes is null\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Microsoft.AutoGen/Core.Grpc/GrpcAgentRuntime.cs","lineNumber":226,"sourceCode":"            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\n            };\n        }\n\n        var messageId = evt.Id;\n        var typeName = evt.Attributes[Constants.DATA_SCHEMA_ATTR].CeString;\n\n        var messageContext = new MessageContext(messageId, cancellationToken)\n        {","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/Microsoft.AutoGen/Core.Grpc/GrpcAgentRuntime.cs#L208-L244","documentation":"Thrown by GrpcAgentRuntime.HandlePublish when the incoming CloudEvent has a null Attributes map. The runtime reads Attributes to recover the sender agent (type and key attributes), so an event without an attributes map is considered malformed and rejected before topic routing.","triggerScenarios":"Receiving a CloudEvent over gRPC whose attributes map was never populated; hand-constructed CloudEvent objects in tests or bridges that set only Type, Source, and ProtoData; protobuf messages where optional map fields default-skipped on the wire and arrive as null on the .NET side.","commonSituations":"Interop with external CloudEvent producers that omit the attributes extension map; partial construction of CloudEvent in custom middleware; schema drift between client and service protobuf definitions.","solutions":["Populate the CloudEvent attributes map (at minimum the sender type/key attributes, or an empty map) before publishing","Use the library's publish APIs rather than raw CloudEvent construction so attributes are set automatically","Regenerate/align the protobuf contract between publisher and runtime so the attributes map is transmitted"],"exampleFix":"// before\nvar evt = new CloudEvent { Type = t, Source = s, ProtoData = Any.Pack(msg) };\n\n// after\nvar evt = new CloudEvent\n{\n    Type = t,\n    Source = s,\n    ProtoData = Any.Pack(msg),\n    Attributes =\n    {\n        [Constants.AGENT_SENDER_TYPE_ATTR] = new CloudEventAttributeValue { CeString = agentType },\n        [Constants.AGENT_SENDER_KEY_ATTR] = new CloudEventAttributeValue { CeString = agentKey }\n    }\n};","handlingStrategy":"validation","validationCode":"bool IsValidEvent(CloudEvent evt) => evt is not null && evt.Attributes is not null && evt.ProtoData is not null;","typeGuard":"static bool IsWellFormed(CloudEvent evt) => evt?.Attributes is not null && evt?.ProtoData is not null;","tryCatchPattern":"try { await HandlePublish(evt); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"Attributes\")) { _logger.LogWarning(ex, \"Malformed CloudEvent missing attributes\"); }","preventionTips":["Include the attributes map (with sender attributes) in every published CloudEvent","Validate event shape at ingress before it reaches the runtime"],"tags":["grpc","cloudevent","attributes","null-check"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}