{"record":{"id":"26a70157d50029ea","repo":"microsoft/semantic-kernel","slug":"topicid-does-not-match-the-subscription-26a701","errorCode":null,"errorMessage":"TopicId does not match the subscription.","messagePattern":"TopicId does not match the subscription\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Agents/Runtime/Core/TypeSubscription.cs","lineNumber":71,"sourceCode":"    /// </summary>\n    /// <param name=\"topic\">The topic to check.</param>\n    /// <returns><c>true</c> if the topic's type matches exactly, <c>false</c> otherwise.</returns>\n    public bool Matches(TopicId topic)\n    {\n        return topic.Type == this.TopicType;\n    }\n\n    /// <summary>\n    /// Maps a <see cref=\"TopicId\"/> to an <see cref=\"AgentId\"/>. Should only be called if <see cref=\"Matches\"/> returns true.\n    /// </summary>\n    /// <param name=\"topic\">The topic to map.</param>\n    /// <returns>An <see cref=\"AgentId\"/> representing the agent that should handle the topic.</returns>\n    /// <exception cref=\"InvalidOperationException\">Thrown if the topic does not match the subscription.</exception>\n    public AgentId MapToAgent(TopicId topic)\n    {\n        if (!this.Matches(topic))\n        {\n            throw new InvalidOperationException(\"TopicId does not match the subscription.\");\n        }\n\n        return new AgentId(this.AgentType, topic.Source);\n    }\n\n    /// <summary>\n    /// Determines whether the specified object is equal to the current subscription.\n    /// </summary>\n    /// <param name=\"obj\">The object to compare with the current instance.</param>\n    /// <returns><c>true</c> if the specified object is equal to this instance; otherwise, <c>false</c>.</returns>\n    public override bool Equals([NotNullWhen(true)] object? obj)\n    {\n        return\n            obj is TypeSubscription other &&\n                (this.Id == other.Id ||\n                    (this.AgentType == other.AgentType &&\n                        this.TopicType == other.TopicType));\n    }","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Agents/Runtime/Core/TypeSubscription.cs#L53-L89","documentation":"TypeSubscription.MapToAgent checks Matches(topic) (exact equality topic.Type == TopicType) and throws InvalidOperationException if it does not. As with the prefix variant, the runtime calls Matches before MapToAgent, so this throw signals direct misuse or a topic/subscription mismatch.","triggerScenarios":"Calling subscription.MapToAgent(topic) directly without a prior Matches check; a topic whose Type differs from the subscription's exact TopicType; a typo or casing mismatch between published topic type and TopicType (matching is ordinal/case-sensitive).","commonSituations":"Casing differences between the published TopicId.Type and the registered TopicType; manual mapping code; publishing to a topic type that has no matching subscription.","solutions":["Guard with `if (subscription.Matches(topic))` before MapToAgent.","Ensure the published topic type exactly equals the subscription's TopicType (including casing).","Prefer using the runtime's publish path so Matches is always checked."],"exampleFix":"// before\nvar agentId = subscription.MapToAgent(topic);\n\n// after\nif (!subscription.Matches(topic)) return;\nvar agentId = subscription.MapToAgent(topic);","handlingStrategy":"validation","validationCode":"if (!subscription.Matches(topic))\n{\n    return; // topic type does not exactly match\n}\nAgentId target = subscription.MapToAgent(topic);","typeGuard":"bool Handles(TypeSubscription sub, TopicId t) => string.Equals(t.Type, sub.TopicType, StringComparison.Ordinal);","tryCatchPattern":null,"preventionTips":["Match topic type casing exactly against TopicType.","Call Matches() before MapToAgent().","Prefer the runtime's publish path so the check is always performed."],"tags":["subscription","type","topic","runtime","dotnet"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}