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

After the state-loading logic (either deserializing from persisted JSON or deriving from the step type), ActivateStepAsync checks that both stateType and stateObject are non-null. If either is null, this KernelException is thrown. This is a defensive guard against an unexpected failure in the state resolution pipeline.

Source

Thrown at dotnet/src/Experimental/Process.Runtime.Dapr/Actors/StepActor.cs:407

            }

            var stateObjectJson = await this.StateManager.GetStateAsync<string>(ActorStateKeys.StepStateJson).ConfigureAwait(false);
            stateObject = JsonSerializer.Deserialize(stateObjectJson, stateType) as KernelProcessStepState;
        }
        else
        {
            stateType = this._innerStepType.ExtractStateType(out Type? userStateType, this._logger);
            stateObject = this._stepInfo.State;

            // Persist the state type and type object.
            await this.StateManager.AddStateAsync(ActorStateKeys.StepStateType, stateType.AssemblyQualifiedName).ConfigureAwait(false);
            await this.StateManager.AddStateAsync(ActorStateKeys.StepStateJson, JsonSerializer.Serialize(stateObject)).ConfigureAwait(false);
            await this.StateManager.SaveStateAsync().ConfigureAwait(false);
        }

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

        MethodInfo? methodInfo =
            this._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;
        this._stepStateType = stateType;

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

        await stepInstance.ActivateAsync(stateObject).ConfigureAwait(false);
        await activateTask.ConfigureAwait(false);
    }

    /// <summary>

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Inspect the persisted StepStateJson in the Dapr state store for null or malformed content and clear it if corrupted.
  2. Ensure the state type's DataContract/DataMember attributes are consistent between serialization and deserialization.
  3. Clear all persisted state (StepStateType, StepStateJson, StepInfoState) and let the actor re-initialize from scratch.
Defensive patterns

Strategy: try-catch

Validate before calling

// Validate persisted state JSON before activation:
var stepStateJson = await stateManager.TryGetStateAsync<string>(ActorStateKeys.StepStateJson);
if (stepStateJson.HasValue && (string.IsNullOrWhiteSpace(stepStateJson.Value) || stepStateJson.Value.Trim() == "null"))
{
    logger.LogWarning("Persisted StepStateJson is null or empty. Clearing to allow re-derivation.");
    // Clear persisted state
}

Try / catch

try
{
    await stepActor.PrepareIncomingMessagesAsync();
}
catch (KernelException ex) when (ex.Message.Contains("state object for the KernelProcessStep could not be created"))
{
    logger.LogError("State object creation failed. Inspect persisted StepStateJson for corruption. Clear Dapr state to re-initialize.");
}

Prevention

When it happens

Trigger: stateObject is null when JSON deserialization of StepStateJson produces null (e.g. the JSON is 'null' or the deserialized object's cast to KernelProcessStepState yields null). stateType is null when Type.GetType fails but somehow bypassed the earlier null check (should not happen under normal logic).

Common situations: The persisted StepStateJson contains 'null' or malformed JSON that deserializes to null. A JSON serialization mismatch where the deserializer cannot map the JSON to the expected KernelProcessStepState-derived type, yielding a null result from the 'as' cast.

Related errors


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