microsoft/autogen · error · Exception

Could not find a serializer for message of type {typeName}

Error message

Could not find a serializer for message of type {typeName}

What it means

Thrown in strict mode when HandlePublish cannot find an IMessageSerializer for the CloudEvent's type name. The runtime first tries the serialization registry, then retries after ensuring the recipient agent exists (which may register its contracts); if no serializer is registered and _strictMessageDeserialization is true, it throws instead of logging a warning. Non-strict mode merely logs and drops the message.

Source

Thrown at dotnet/src/Microsoft.AutoGen/Core.Grpc/GrpcAgentRuntime.cs:272

        // Iterate over subscriptions values to find receiving agents
        foreach (var subscription in this._agentsContainer.Subscriptions.Values)
        {
            if (subscription.Matches(topic))
            {
                var recipient = subscription.MapToAgent(topic);
                var agent = await this._agentsContainer.EnsureAgentAsync(recipient);

                // give the serializer a second chance to have been registered
                serializer ??= SerializationRegistry.GetSerializer(typeName);

                if (serializer != null)
                {
                    message ??= serializer.Deserialize(evt.ProtoData);
                    await agent.OnMessageAsync(message, messageContext);
                }
                else if (_strictMessageDeserialization)
                {
                    throw new Exception($"Could not find a serializer for message of type {typeName}");

                }
                else
                {
                    _logger.LogWarning($"Could not find a serializer for message of type {typeName}; this is likely due there not yet being an instantiated agent with a contract for it.");
                }
            }
        }
    }

    public async ValueTask StartAsync(CancellationToken cancellationToken)
    {
        await this._messageRouter.StartAsync(cancellationToken);
        if (this._agentsContainer.RegisteredAgentTypes.Count > 0)
        {
            foreach (var type in this._agentsContainer.RegisteredAgentTypes)
            {
                await this._client.RegisterAgentAsync(new RegisterAgentTypeRequest

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Register a serializer for the message type before it arrives (e.g. register the protobuf contract in the SerializationRegistry or ensure an agent with that contract is instantiated in this process)
  2. Verify the message type name in the CloudEvent matches a registered contract exactly (namespace-qualified name / proto full name)
  3. If dropping unknown types is acceptable, disable strict message deserialization in the runtime configuration so the runtime logs a warning instead of throwing

Example fix

// before
// agent subscribed to topic with message type not known in this worker
builder.AddSubscription<StaticSubscription>(...); // strict mode throws

// after
// register the contract so the serializer exists before delivery
SerializationRegistry.RegisterSerializer(new ProtobufMessageSerializer(typeof(MyMessage)), "my.package.MyMessage");
Defensive patterns

Strategy: fallback

Validate before calling

var typeName = evt.ProtoData.TypeUrl.Split('.').Last();
if (SerializationRegistry.GetSerializer(typeName) is null && !strictMode) { /* log and skip */ }

Try / catch

try { await runtime.OnMessageAsync(msg); } catch (Exception ex) when (ex.Message.Contains("Could not find a serializer")) { _logger.LogWarning(ex, "No serializer for {Type}; message dropped", typeName); }

Prevention

When it happens

Trigger: Subscribing an agent to a topic whose events carry a message type the process never registered a serializer for; receiving an event for a type defined in an assembly not loaded at runtime; strict message deserialization enabled in the runtime options while publishing unregistered message types.

Common situations: Cross-process deployments where the worker handling a subscription doesn't reference the message contract assembly; enabling strict mode after previously tolerating unknown types; message type name mismatches after renaming protobuf/message types.

Related errors


AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15). Data as JSON: /api/errors/a11233893a5ec921. Report an issue: GitHub.