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

  1. Create the directory before saving: Directory.CreateDirectory(Path.GetDirectoryName(fullFilepath)!).
  2. Use an existing directory such as Path.GetTempPath() for the base.
  3. 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

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


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