microsoft/semantic-kernel · error · KernelException
Filepath {filepath} does not exist
Error message
Filepath {filepath} does not exist What it means
A KernelException thrown by GetRepositoryProcessStateFilepath when checkFilepathExists is true and the constructed process-state JSON file does not exist on disk. It guards callers that require a pre-existing process-state file to load.
Source
Thrown at dotnet/samples/GettingStartedWithProcesses/Utilities/ProcessStateMetadataUtilities.cs:43
}
public static KernelProcessStateMetadata? LoadProcessStateMetadata(string jsonRelativePath)
{
var filepath = GetRepositoryProcessStateFilepath(jsonRelativePath, checkFilepathExists: true);
Console.WriteLine($"Loading ProcessStateMetadata from:\n'{Path.GetFullPath(filepath)}'");
using StreamReader reader = new(filepath);
var content = reader.ReadToEnd();
return JsonSerializer.Deserialize<KernelProcessStateMetadata>(content, s_jsonOptions);
}
private static string GetRepositoryProcessStateFilepath(string jsonRelativePath, bool checkFilepathExists = false)
{
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"))View on GitHub (pinned to c028a0c7dc)
Solutions
- Verify the expected JSON file exists under the source directory and the relative path is correct.
- Generate/save the process state first via StoreProcessStateLocally before loading.
- Confirm s_currentSourceDir resolves to the intended folder (check working directory).
Example fix
// before
var meta = ProcessStateMetadataUtilities.Load(..., "missing.json");
// after - assert existence with a clear path first
string expected = Path.Combine(sourceDir, "missing.json");
if (!File.Exists(expected)) throw new FileNotFoundException("Process state JSON not found", expected); Defensive patterns
Strategy: validation
Validate before calling
string path = Path.Combine(sourceDir, jsonRelativePath);
if (!File.Exists(path)) throw new FileNotFoundException("Process state JSON not found", path); Type guard
bool ProcessStateExists(string sourceDir, string rel) => File.Exists(Path.Combine(sourceDir, rel));
Try / catch
try { return LoadProcessStateMetadata(rel); }
catch (KernelException ex) when (ex.Message.Contains("does not exist")) { /* generate state first or correct path */ } Prevention
- Generate process state files before referencing them.
- Pin jsonRelativePath to committed fixtures.
- Log s_currentSourceDir to catch working-directory drift.
When it happens
Trigger: Calling a load helper that sets checkFilepathExists=true with a jsonRelativePath that does not resolve to an existing file under s_currentSourceDir.
Common situations: Test fixture references a process-state JSON that was never committed/generated; wrong relative path; file moved/renamed; running from a different working directory shifting s_currentSourceDir.
Related errors
- Directory for path '{fullFilepath}' does not exist, could no
- Filepath for process {processStateInfo.Name} does not have .
- Failed to get a response from the chat completion service.
- Configuration section '{section}' not found
- Configuration not found, please setup the notebooks first us
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/c9a8be5cb540e254.
Report an issue: GitHub.