microsoft/semantic-kernel · error · KernelException
Directory for path '{fullFilepath}' does not exist, could no
Error message
Directory for path '{fullFilepath}' does not exist, could not save process {processStateInfo.Name} What it means
A KernelException thrown by StoreProcessStateLocally when the directory portion of fullFilepath does not exist. The utility refuses to save the serialized process state into a missing directory rather than auto-creating it.
Source
Thrown at dotnet/samples/GettingStartedWithProcesses/Utilities/ProcessStateMetadataUtilities.cs:58
string filepath = Path.Combine(s_currentSourceDir, jsonRelativePath);
if (checkFilepathExists && !File.Exists(filepath))
{
throw new KernelException($"Filepath {filepath} does not exist");
}
return filepath;
}
/// <summary>
/// Function that stores the definition of the SK Process State`.<br/>
/// </summary>
/// <param name="processStateInfo">Process State to be stored</param>
/// <param name="fullFilepath">Filepath to store definition of process in json format</param>
private static void StoreProcessStateLocally(KernelProcessStateMetadata processStateInfo, string fullFilepath)
{
if (!(Path.GetDirectoryName(fullFilepath) is string directory && Directory.Exists(directory)))
{
throw new KernelException($"Directory for path '{fullFilepath}' does not exist, could not save process {processStateInfo.Name}");
}
if (!(Path.GetExtension(fullFilepath) is string extension && !string.IsNullOrEmpty(extension) && extension == ".json"))
{
throw new KernelException($"Filepath for process {processStateInfo.Name} does not have .json extension");
}
string content = JsonSerializer.Serialize(processStateInfo, s_jsonOptions);
Console.WriteLine($"Process State: \n{content}");
Console.WriteLine($"Saving Process State Locally: \n{Path.GetFullPath(fullFilepath)}");
File.WriteAllText(fullFilepath, content);
}
}
View on GitHub (pinned to c028a0c7dc)
Solutions
- Create the directory before saving: Directory.CreateDirectory(Path.GetDirectoryName(fullFilepath)!).
- Use an existing directory such as Path.GetTempPath() for the base.
- Validate directory existence up front and report the offending path.
Example fix
// before StoreProcessStateLocally(state, @"C:\out\state.json"); // C:\out missing // after string dir = Path.GetDirectoryName(fullFilepath)!; Directory.CreateDirectory(dir); StoreProcessStateLocally(state, fullFilepath);
Defensive patterns
Strategy: validation
Validate before calling
string dir = Path.GetDirectoryName(fullFilepath)!; Directory.CreateDirectory(dir);
Type guard
bool DirectoryForPathExists(string p) { var d = Path.GetDirectoryName(p); return d is not null && Directory.Exists(d); } Try / catch
try { StoreProcessStateLocally(state, fullFilepath); }
catch (KernelException ex) when (ex.Message.Contains("does not exist")) { Directory.CreateDirectory(Path.GetDirectoryName(fullFilepath)!); /* retry */ } Prevention
- Create output directories before saving.
- Use known-good bases like Path.GetTempPath().
- Validate directory existence early with a clear path in the error.
When it happens
Trigger: Calling StoreProcessStateLocally (or a save helper) with a fullFilepath whose parent directory has not been created.
Common situations: Output directory never created; path built from a base that does not exist; CI/sandbox without the expected folder.
Related errors
- Filepath {filepath} does not exist
- Filepath for process {processStateInfo.Name} does not have .
- The directory '{directoryPath}' does not exist.
- File '{fileName}' not found.
- BERT summary evaluation score ({f1}) is lower than threshold
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/f240dcd5288f54d1.
Report an issue: GitHub.