microsoft/semantic-kernel · error · ArgumentException

ProcessMapBuilder may not target another ProcessMapBuilder.

Error message

ProcessMapBuilder may not target another ProcessMapBuilder.

What it means

Thrown by SendEventTo_Internal when the source step is a ProcessMapBuilder and the resolved target is also a ProcessMapBuilder. The framework explicitly forbids a map step from directly targeting another map step, so a ProcessMapBuilder cannot be wired into another ProcessMapBuilder.

Source

Thrown at dotnet/src/Experimental/Process.Core/ProcessStepEdgeBuilder.cs:125

    /// <summary>
    /// Internally overridable implementation: Signals that the output of the source step should be sent to the specified target when the associated event fires.
    /// </summary>
    /// <param name="target">The output target.</param>
    /// <returns>A fresh builder instance for fluid definition</returns>
    /// <exception cref="InvalidOperationException"></exception>
    /// <exception cref="ArgumentException"></exception>
    internal virtual ProcessStepEdgeBuilder SendEventTo_Internal(ProcessTargetBuilder target)
    {
        if (this.Target is not null)
        {
            throw new InvalidOperationException("An output target has already been set.");
        }

        if (target is ProcessFunctionTargetBuilder functionTargetBuilder)
        {
            if (functionTargetBuilder.Step is ProcessMapBuilder && this.Source is ProcessMapBuilder)
            {
                throw new ArgumentException($"{nameof(ProcessMapBuilder)} may not target another {nameof(ProcessMapBuilder)}.", nameof(target));
            }
        }

        this.Target = target;
        this.Source.LinkTo(this.EventData.EventId, this);

        return new ProcessStepEdgeBuilder(this.Source, this.EventData.EventId, this.EventData.EventName, this.EdgeGroupBuilder, this.Condition);
    }

    /// <summary>
    /// Emit the SK step event as an external event with specific topic name
    /// </summary>
    /// <returns></returns>
    public ProcessStepEdgeBuilder EmitExternalEvent(ProcessProxyBuilder proxyStep, string topicName)
    {
        // 1. Link sk event and topic
        proxyStep.LinkTopicToStepEdgeInfo(topicName, this.Source, this.EventData);

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Insert a non-map intermediate step (a regular KernelProcessStep) between the two ProcessMapBuilder steps so the edge is map -> step -> map.
  2. Reconsider whether the two maps can be merged into a single ProcessMapBuilder.
  3. If the target map was meant to consume the source map's output, route via a proxy/relay step that forwards the message.

Example fix

// before: map -> map (throws)
mapA.OnEvent("Out").SendEventTo(mapB.GetTarget());

// after: map -> relay step -> map
mapA.OnEvent("Out").SendEventTo(relayStep.GetTarget());
relayStep.OnEvent("Out").SendEventTo(mapB.GetTarget());
Defensive patterns

Strategy: validation

Validate before calling

if (source is ProcessMapBuilder && target.Step is ProcessMapBuilder)
    throw new InvalidOperationException("Insert a non-map step between two ProcessMapBuilder steps.");

Type guard

static bool IsMapToMap(ProcessStepBuilder src, ProcessFunctionTargetBuilder tgt) => src is ProcessMapBuilder && tgt.Step is ProcessMapBuilder;

Try / catch

try { edge.SendEventTo(mapTarget); }
catch (ArgumentException ex) when (ex.Message.Contains("may not target another"))
{ /* route through an intermediate non-map step */ }

Prevention

When it happens

Trigger: Calling SendEventTo with a function target whose Step is a ProcessMapBuilder, from an edge whose Source is itself a ProcessMapBuilder (map-to-map wiring).

Common situations: Composing nested map operations and trying to chain one map directly into another; modeling pipelines where two ProcessMapBuilder steps are adjacent without an intermediate step.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/6e4b79c81f2d6250. Report an issue: GitHub.