{"record":{"id":"ac2112e66ceefb4e","repo":"microsoft/semantic-kernel","slug":"type-stepstatetype-value-is-not-a-valid-kernel","errorCode":null,"errorMessage":"Type '{stepStateType.Value}' is not a valid KernelProcessStepState type.","messagePattern":"Type '(.+?)' is not a valid KernelProcessStepState type\\.","errorType":"exception","errorClass":"KernelException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Experimental/Process.Runtime.Dapr/Actors/StepActor.cs","lineNumber":388,"sourceCode":"        this._inputs = this._initialInputs.ToDictionary(kvp => kvp.Key, kvp => kvp.Value?.ToDictionary(kvp => kvp.Key, kvp => kvp.Value));\n\n        // Activate the step with user-defined state if needed\n        KernelProcessStepState? stateObject = null;\n        Type? stateType = null;\n\n        // Check if the state has already been persisted\n        var stepStateType = await this.StateManager.TryGetStateAsync<string>(ActorStateKeys.StepStateType).ConfigureAwait(false);\n        if (stepStateType.HasValue)\n        {\n            stateType = Type.GetType(stepStateType.Value);\n            if (stateType is null)\n            {\n                throw new KernelException($\"Type '{stepStateType.Value}' could not be resolved to a valid KernelProcessStepState type.\").Log(this._logger);\n            }\n\n            if (!typeof(KernelProcessStepState).IsAssignableFrom(stateType))\n            {\n                throw new KernelException($\"Type '{stepStateType.Value}' is not a valid KernelProcessStepState type.\").Log(this._logger);\n            }\n\n            var stateObjectJson = await this.StateManager.GetStateAsync<string>(ActorStateKeys.StepStateJson).ConfigureAwait(false);\n            stateObject = JsonSerializer.Deserialize(stateObjectJson, stateType) as KernelProcessStepState;\n        }\n        else\n        {\n            stateType = this._innerStepType.ExtractStateType(out Type? userStateType, this._logger);\n            stateObject = this._stepInfo.State;\n\n            // Persist the state type and type object.\n            await this.StateManager.AddStateAsync(ActorStateKeys.StepStateType, stateType.AssemblyQualifiedName).ConfigureAwait(false);\n            await this.StateManager.AddStateAsync(ActorStateKeys.StepStateJson, JsonSerializer.Serialize(stateObject)).ConfigureAwait(false);\n            await this.StateManager.SaveStateAsync().ConfigureAwait(false);\n        }\n\n        if (stateType is null || stateObject is null)\n        {","sourceCodeStart":370,"sourceCodeEnd":406,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Experimental/Process.Runtime.Dapr/Actors/StepActor.cs#L370-L406","documentation":"After resolving the persisted state type via Type.GetType, ActivateStepAsync validates that it inherits from KernelProcessStepState. If it does not, this KernelException is thrown. Only KernelProcessStepState-derived types (including KernelProcessStepState<TState>) can be used as step state.","triggerScenarios":"The persisted StepStateType resolves to a CLR type, but that type is not assignable to KernelProcessStepState. This indicates the persisted state was corrupted, manually tampered with, or a non-state type name was persisted.","commonSituations":"Corrupted Dapr state store entries where StepStateType holds a non-state type name. A custom serialization issue that wrote the wrong type name. A migration that replaced the state type with an incompatible type that no longer inherits from KernelProcessStepState.","solutions":["Clear the persisted StepStateType and StepStateJson from the Dapr state store so the actor re-derives the correct state type from the step type.","If the state type legitimately changed, ensure the new type still inherits from KernelProcessStepState.","Audit the Dapr state store to confirm StepStateType contains a valid KernelProcessStepState-derived type name."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Validate persisted state type before activation:\nvar stepStateType = await stateManager.TryGetStateAsync<string>(ActorStateKeys.StepStateType);\nif (stepStateType.HasValue)\n{\n    Type? t = Type.GetType(stepStateType.Value);\n    if (t is not null && !typeof(KernelProcessStepState).IsAssignableFrom(t))\n    {\n        logger.LogWarning(\"Persisted state type '{Type}' is not a KernelProcessStepState. Clearing state.\", stepStateType.Value);\n        // Clear persisted state to allow re-derivation\n    }\n}","typeGuard":"static bool IsValidStateType(string assemblyQualifiedName)\n{\n    var t = Type.GetType(assemblyQualifiedName);\n    return t is not null && typeof(KernelProcessStepState).IsAssignableFrom(t);\n}","tryCatchPattern":"try\n{\n    await stepActor.PrepareIncomingMessagesAsync();\n}\ncatch (KernelException ex) when (ex.Message.Contains(\"not a valid KernelProcessStepState type\"))\n{\n    logger.LogError(\"Persisted state type is invalid. Clear Dapr state store entries for this actor.\");\n}","preventionTips":["Do not manually edit or corrupt persisted StepStateType values in the Dapr state store.","Ensure state type migrations preserve KernelProcessStepState inheritance.","Clear persisted state when the state type hierarchy changes."],"tags":["dapr","process-runtime","type-validation","persisted-state","semantic-kernel"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}