{"record":{"id":"f240dcd5288f54d1","repo":"microsoft/semantic-kernel","slug":"directory-for-path-fullfilepath-does-not-exist","errorCode":null,"errorMessage":"Directory for path '{fullFilepath}' does not exist, could not save process {processStateInfo.Name}","messagePattern":"Directory for path '(.+?)' does not exist, could not save process (.+?)","errorType":"exception","errorClass":"KernelException","httpStatus":null,"severity":"error","filePath":"dotnet/samples/GettingStartedWithProcesses/Utilities/ProcessStateMetadataUtilities.cs","lineNumber":58,"sourceCode":"        string filepath = Path.Combine(s_currentSourceDir, jsonRelativePath);\n        if (checkFilepathExists && !File.Exists(filepath))\n        {\n            throw new KernelException($\"Filepath {filepath} does not exist\");\n        }\n\n        return filepath;\n    }\n\n    /// <summary>\n    /// Function that stores the definition of the SK Process State`.<br/>\n    /// </summary>\n    /// <param name=\"processStateInfo\">Process State to be stored</param>\n    /// <param name=\"fullFilepath\">Filepath to store definition of process in json format</param>\n    private static void StoreProcessStateLocally(KernelProcessStateMetadata processStateInfo, string fullFilepath)\n    {\n        if (!(Path.GetDirectoryName(fullFilepath) is string directory && Directory.Exists(directory)))\n        {\n            throw new KernelException($\"Directory for path '{fullFilepath}' does not exist, could not save process {processStateInfo.Name}\");\n        }\n\n        if (!(Path.GetExtension(fullFilepath) is string extension && !string.IsNullOrEmpty(extension) && extension == \".json\"))\n        {\n            throw new KernelException($\"Filepath for process {processStateInfo.Name} does not have .json extension\");\n        }\n\n        string content = JsonSerializer.Serialize(processStateInfo, s_jsonOptions);\n        Console.WriteLine($\"Process State: \\n{content}\");\n        Console.WriteLine($\"Saving Process State Locally: \\n{Path.GetFullPath(fullFilepath)}\");\n        File.WriteAllText(fullFilepath, content);\n    }\n}\n","sourceCodeStart":40,"sourceCodeEnd":72,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/samples/GettingStartedWithProcesses/Utilities/ProcessStateMetadataUtilities.cs#L40-L72","documentation":"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.","triggerScenarios":"Calling StoreProcessStateLocally (or a save helper) with a fullFilepath whose parent directory has not been created.","commonSituations":"Output directory never created; path built from a base that does not exist; CI/sandbox without the expected folder.","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."],"exampleFix":"// before\nStoreProcessStateLocally(state, @\"C:\\out\\state.json\"); // C:\\out missing\n// after\nstring dir = Path.GetDirectoryName(fullFilepath)!; Directory.CreateDirectory(dir);\nStoreProcessStateLocally(state, fullFilepath);","handlingStrategy":"validation","validationCode":"string dir = Path.GetDirectoryName(fullFilepath)!;\nDirectory.CreateDirectory(dir);","typeGuard":"bool DirectoryForPathExists(string p) { var d = Path.GetDirectoryName(p); return d is not null && Directory.Exists(d); }","tryCatchPattern":"try { StoreProcessStateLocally(state, fullFilepath); }\ncatch (KernelException ex) when (ex.Message.Contains(\"does not exist\")) { Directory.CreateDirectory(Path.GetDirectoryName(fullFilepath)!); /* retry */ }","preventionTips":["Create output directories before saving.","Use known-good bases like Path.GetTempPath().","Validate directory existence early with a clear path in the error."],"tags":["processes","filesystem","directory","kernel-exception"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}