microsoft/autogen · error · InvalidOperationException
Attributes is null.
Error message
Attributes is null.
What it means
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.
Source
Thrown at dotnet/src/Microsoft.AutoGen/Core.Grpc/GrpcAgentRuntime.cs:226
var payload = request.Payload;
var message = payload.ToObject(SerializationRegistry);
resultSink.SetResult(message);
}
}
private async ValueTask HandlePublish(CloudEvent evt, CancellationToken cancellationToken = default)
{
if (evt is null)
{
throw new InvalidOperationException("CloudEvent is null.");
}
if (evt.ProtoData is null)
{
throw new InvalidOperationException("ProtoData is null.");
}
if (evt.Attributes is null)
{
throw new InvalidOperationException("Attributes is null.");
}
var topic = new TopicId(evt.Type, evt.Source);
Contracts.AgentId? sender = null;
if (evt.Attributes.TryGetValue(Constants.AGENT_SENDER_TYPE_ATTR, out var typeValue) && evt.Attributes.TryGetValue(Constants.AGENT_SENDER_KEY_ATTR, out var keyValue))
{
sender = new Contracts.AgentId
{
Type = typeValue.CeString,
Key = keyValue.CeString
};
}
var messageId = evt.Id;
var typeName = evt.Attributes[Constants.DATA_SCHEMA_ATTR].CeString;
var messageContext = new MessageContext(messageId, cancellationToken)
{View on GitHub (pinned to 027ecf0a37)
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
Example fix
// before
var evt = new CloudEvent { Type = t, Source = s, ProtoData = Any.Pack(msg) };
// after
var evt = new CloudEvent
{
Type = t,
Source = s,
ProtoData = Any.Pack(msg),
Attributes =
{
[Constants.AGENT_SENDER_TYPE_ATTR] = new CloudEventAttributeValue { CeString = agentType },
[Constants.AGENT_SENDER_KEY_ATTR] = new CloudEventAttributeValue { CeString = agentKey }
}
}; Defensive patterns
Strategy: validation
Validate before calling
bool IsValidEvent(CloudEvent evt) => evt is not null && evt.Attributes is not null && evt.ProtoData is not null;
Type guard
static bool IsWellFormed(CloudEvent evt) => evt?.Attributes is not null && evt?.ProtoData is not null;
Try / catch
try { await HandlePublish(evt); } catch (InvalidOperationException ex) when (ex.Message.Contains("Attributes")) { _logger.LogWarning(ex, "Malformed CloudEvent missing attributes"); } Prevention
- Include the attributes map (with sender attributes) in every published CloudEvent
- Validate event shape at ingress before it reaches the runtime
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- ProtoData is null.
- Response is null.
- Unknown attribute kind
- Function name cannot be null
- Parameter name cannot be null
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/b14e14037b6f4979.
Report an issue: GitHub.