microsoft/semantic-kernel · error · KernelException

The state object for the KernelProcessStep could not be crea

Error message

The state object for the KernelProcessStep could not be created.

What it means

Thrown by LocalStep.InitializeStepAsync when stateObject (this._stepInfo.State) is null after calling InitializeUserState. Since KernelProcessStepState is a reference type and stateObject is assigned from this._stepInfo.State, this check guards against a null state reference passed in the step info. In practice this fires if the step's State was never set or was explicitly set to null.

Source

Thrown at dotnet/src/Experimental/Process.LocalRuntime/LocalStep.cs:307

        if (this._stepInfo is KernelProcessAgentStep agentStep)
        {
            this._initialInputs = this.FindInputChannels(this._functions, this._logger, this.ExternalMessageChannel, agentStep.AgentDefinition);
        }
        else
        {
            this._initialInputs = this.FindInputChannels(this._functions, this._logger, this.ExternalMessageChannel);
        }

        this._inputs = this._initialInputs.ToDictionary(kvp => kvp.Key, kvp => kvp.Value?.ToDictionary(kvp => kvp.Key, kvp => kvp.Value));

        // Activate the step with user-defined state if needed
        Type stateType = this._stepInfo.InnerStepType.ExtractStateType(out Type? userStateType, this._logger);
        KernelProcessStepState stateObject = this._stepInfo.State;
        stateObject.InitializeUserState(stateType, userStateType);

        if (stateObject is null)
        {
            throw new KernelException("The state object for the KernelProcessStep could not be created.").Log(this._logger);
        }

        MethodInfo methodInfo =
            this._stepInfo.InnerStepType.GetMethod(nameof(KernelProcessStep.ActivateAsync), [stateType]) ??
            throw new KernelException("The ActivateAsync method for the KernelProcessStep could not be found.").Log(this._logger);

        this._stepState = stateObject;

        ValueTask activateTask =
            (ValueTask?)methodInfo.Invoke(this._stepInstance, [stateObject]) ??
            throw new KernelException("The ActivateAsync method failed to complete.").Log(this._logger);

        await this._stepInstance.ActivateAsync(stateObject).ConfigureAwait(false);
        await activateTask.ConfigureAwait(false);
    }

    /// <summary>
    /// Deinitializes the step

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Ensure KernelProcessStepInfo is always constructed with a non-null KernelProcessStepState.
  2. If the step uses a user state type, ensure that type has a public parameterless constructor.
  3. Check deserialization paths to verify the state is fully populated.

Example fix

// before - null state
var stepInfo = new KernelProcessStepInfo(stepType, state: null, edges);
// after - provide a state object
var stepInfo = new KernelProcessStepInfo(stepType, new KernelProcessStepState("MyStep", version: 1), edges);
Defensive patterns

Strategy: validation

Validate before calling

// Verify step state is non-null before building the process
foreach (var step in process.Steps)
{
    if (step.State is null) { throw new InvalidOperationException($"Step '{step}' has null state."); }
}

Prevention

When it happens

Trigger: A KernelProcessStepInfo is constructed with a null KernelProcessStepState, or InitializeUserState sets internal state to null for a step type that requires user state but the state initialization logic returns null.

Common situations: Manually constructing KernelProcessStepInfo with a null State; deserialization producing a step info with missing state; a step type whose user state type cannot be instantiated (no parameterless constructor) causing InitializeUserState to fail silently.

Related errors


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