{"record":{"id":"4b00894cec4a80f6","repo":"dotnet/orleans","slug":"cannot-find-file-filename","errorCode":null,"errorMessage":"Cannot find file {filename}","messagePattern":"Cannot find file (.+?)","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"samples/Streaming/Common/Secrets.cs","lineNumber":38,"sourceCode":"        EventHubConnectionString = eventHubConnectionString\n            ?? throw new ArgumentException(\n                \"Must provide an eventHubConnectionString\", nameof(eventHubConnectionString));\n    }\n\n    public static Secrets? LoadFromFile(string filename = \"Secrets.json\")\n    {\n        var currentDir = new DirectoryInfo(Directory.GetCurrentDirectory());\n        while (currentDir != null && currentDir.Exists)\n        {\n            var filePath = Path.Combine(currentDir.FullName, filename);\n            if (File.Exists(filePath))\n            {\n                return JsonSerializer.Deserialize<Secrets>(File.ReadAllText(filePath));\n            }\n\n            currentDir = currentDir.Parent;\n        }\n        throw new FileNotFoundException($\"Cannot find file {filename}\");\n    }\n\n    public static Secrets? TryLoadFromFile(string filename = \"Secrets.json\")\n    {\n        var currentDir = new DirectoryInfo(Directory.GetCurrentDirectory());\n        while (currentDir != null && currentDir.Exists)\n        {\n            var filePath = Path.Combine(currentDir.FullName, filename);\n            if (File.Exists(filePath))\n            {\n                var secrets = JsonSerializer.Deserialize<Secrets>(File.ReadAllText(filePath));\n                // Return null if secrets file exists but has empty/missing values\n                if (secrets is null ||\n                    string.IsNullOrWhiteSpace(secrets.DataConnectionString) ||\n                    string.IsNullOrWhiteSpace(secrets.EventHubConnectionString))\n                {\n                    return null;\n                }","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/dotnet/orleans/blob/fca799fa70ecb6ad975224271703ca43221f58de/samples/Streaming/Common/Secrets.cs#L20-L56","documentation":"Thrown by Secrets.LoadFromFile after it walks from the current working directory up through every parent directory looking for the secrets file (default Secrets.json) and cannot find it anywhere in that chain. The Streaming samples use this to load Event Hub / service credentials at runtime.","triggerScenarios":"Calling Secrets.LoadFromFile(\"Secrets.json\") (or TryLoadFromFile used as a non-throwing variant) when Secrets.json is absent from the bin output directory and all of its ancestors up to the filesystem root. Common because the file is git-ignored and must be created per-developer.","commonSituations":"First run of a Streaming sample without copying the provided Secrets.template.json to Secrets.json; running from a working directory that is not under the sample folder; the file was named with a different case on a case-sensitive filesystem.","solutions":["Create samples/Streaming/Common/Secrets.json from the Secrets.template.json (or sample README) and fill in your Event Hub / storage connection strings.","Run the sample from the sample's project directory so the upward directory walk starts near the file.","Prefer Secrets.TryLoadFromFile (returns null instead of throwing) if missing secrets should degrade gracefully rather than crash."],"exampleFix":"// before\nvar secrets = Secrets.LoadFromFile(\"Secrets.json\"); // throws if absent\n\n// after: create the file from the template, or tolerate absence\nvar secrets = Secrets.TryLoadFromFile(\"Secrets.json\");\nif (secrets is null) { Console.WriteLine(\"Configure Secrets.json first.\"); return; }","handlingStrategy":"validation","validationCode":"// Prefer the non-throwing loader and check for null\nvar secrets = Secrets.TryLoadFromFile(\"Secrets.json\");\nif (secrets is null || string.IsNullOrEmpty(secrets.EventHubConnectionString))\n{\n    Console.WriteLine(\"Configure Secrets.json (see Secrets.template.json) before running.\");\n    return;\n}","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Create Secrets.json from the provided template before first run.","Run samples from their project directory so the upward directory walk finds the file.","Use TryLoadFromFile when missing secrets should not be fatal."],"tags":["streaming","secrets","configuration","file-io","sample"],"backgroundTag":null,"analyzedSha":"fca799fa70ecb6ad975224271703ca43221f58de","analyzedAt":"2026-08-13T19:55:57.938Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}