{"record":{"id":"c9a8be5cb540e254","repo":"microsoft/semantic-kernel","slug":"filepath-filepath-does-not-exist","errorCode":null,"errorMessage":"Filepath {filepath} does not exist","messagePattern":"Filepath (.+?) does not exist","errorType":"exception","errorClass":"KernelException","httpStatus":null,"severity":"error","filePath":"dotnet/samples/GettingStartedWithProcesses/Utilities/ProcessStateMetadataUtilities.cs","lineNumber":43,"sourceCode":"    }\n\n    public static KernelProcessStateMetadata? LoadProcessStateMetadata(string jsonRelativePath)\n    {\n        var filepath = GetRepositoryProcessStateFilepath(jsonRelativePath, checkFilepathExists: true);\n\n        Console.WriteLine($\"Loading ProcessStateMetadata from:\\n'{Path.GetFullPath(filepath)}'\");\n\n        using StreamReader reader = new(filepath);\n        var content = reader.ReadToEnd();\n        return JsonSerializer.Deserialize<KernelProcessStateMetadata>(content, s_jsonOptions);\n    }\n\n    private static string GetRepositoryProcessStateFilepath(string jsonRelativePath, bool checkFilepathExists = false)\n    {\n        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\"))","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/samples/GettingStartedWithProcesses/Utilities/ProcessStateMetadataUtilities.cs#L25-L61","documentation":"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.","triggerScenarios":"Calling a load helper that sets checkFilepathExists=true with a jsonRelativePath that does not resolve to an existing file under s_currentSourceDir.","commonSituations":"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.","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)."],"exampleFix":"// before\nvar meta = ProcessStateMetadataUtilities.Load(..., \"missing.json\");\n// after - assert existence with a clear path first\nstring expected = Path.Combine(sourceDir, \"missing.json\");\nif (!File.Exists(expected)) throw new FileNotFoundException(\"Process state JSON not found\", expected);","handlingStrategy":"validation","validationCode":"string path = Path.Combine(sourceDir, jsonRelativePath);\nif (!File.Exists(path)) throw new FileNotFoundException(\"Process state JSON not found\", path);","typeGuard":"bool ProcessStateExists(string sourceDir, string rel) => File.Exists(Path.Combine(sourceDir, rel));","tryCatchPattern":"try { return LoadProcessStateMetadata(rel); }\ncatch (KernelException ex) when (ex.Message.Contains(\"does not exist\")) { /* generate state first or correct path */ }","preventionTips":["Generate process state files before referencing them.","Pin jsonRelativePath to committed fixtures.","Log s_currentSourceDir to catch working-directory drift."],"tags":["processes","filesystem","configuration","kernel-exception"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}