{"record":{"id":"a9213bfddf63f646","repo":"OrchardCMS/OrchardCore","slug":"cannot-get-file-stream-because-the-file-path-does-not-exist-a9213b","errorCode":null,"errorMessage":"Cannot get file stream because the file '{path}' does not exist.","messagePattern":"Cannot get file stream because the file '(.+?)' does not exist\\.","errorType":"exception","errorClass":"FileStoreException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.FileStorage.AzureBlob/BlobFileStore.cs","lineNumber":637,"sourceCode":"        catch (FileStoreException)\n        {\n            throw;\n        }\n        catch (Exception ex)\n        {\n            throw new FileStoreException($\"Cannot copy file '{srcPath}' to '{dstPath}'.\", ex);\n        }\n    }\n\n    public async Task<Stream> GetFileStreamAsync(string path)\n    {\n        try\n        {\n            var blob = GetBlobReference(path);\n\n            if (!await blob.ExistsAsync())\n            {\n                throw new FileStoreException($\"Cannot get file stream because the file '{path}' does not exist.\");\n            }\n\n            return (await blob.DownloadAsync()).Value.Content;\n        }\n        catch (FileStoreException)\n        {\n            throw;\n        }\n        catch (Exception ex)\n        {\n            throw new FileStoreException($\"Cannot get file stream of the file '{path}'.\", ex);\n        }\n    }\n\n    // Reduces the need to call blob.FetchAttributes, and blob.ExistsAsync,\n    // as Azure Storage Library will perform these actions on OpenReadAsync().\n    public Task<Stream> GetFileStreamAsync(IFileStoreEntry fileStoreEntry)\n    {","sourceCodeStart":619,"sourceCodeEnd":655,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.FileStorage.AzureBlob/BlobFileStore.cs#L619-L655","documentation":"GetFileStreamAsync checks whether the blob exists before downloading; if it does not, it throws FileStoreException with this message. This is an explicit not-found signal distinct from storage service errors, which are wrapped by a separate catch.","triggerScenarios":"Calling IFileStore.GetFileStreamAsync(path) (string overload) for a path whose blob does not exist in the container — e.g. path is null/empty, misspelled, points to a directory, or the file was deleted concurrently.","commonSituations":"Rendering media items whose stored URL references a deleted blob; case-sensitivity mismatches on the blob path (Azure paths are case-sensitive); tenant BasePath misconfiguration so relative paths miss the actual blobs.","solutions":["Verify the path exists first with fileStore.GetFileInfoAsync(path) and return a 404 or fallback instead of opening a stream.","Log and correct the path being passed — check spelling, casing, and whether the directory portion matches the store's BasePath.","Check that the file was not deleted by a concurrent process, workflow, or media cleanup job.","Confirm the tenant's media storage connection settings (container and BasePath) point at the location where files were actually stored."],"exampleFix":"// before\nvar stream = await fileStore.GetFileStreamAsync(path);\n// after\nvar file = await fileStore.GetFileInfoAsync(path);\nif (file == null)\n{\n    return NotFound();\n}\nvar stream = await fileStore.GetFileStreamAsync(path);","handlingStrategy":"validation","validationCode":"var file = await fileStore.GetFileInfoAsync(path);\nif (file == null)\n{\n    return null; // or 404 — blob does not exist\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    var stream = await fileStore.GetFileStreamAsync(path);\n}\ncatch (FileStoreException)\n{\n    return Results.NotFound($\"File '{path}' not found.\");\n}","preventionTips":["Always probe with GetFileInfoAsync before opening streams","Keep blob path casing consistent (Azure is case-sensitive)","Check BasePath configuration per tenant","Log deletion workflows that may race with reads"],"tags":["azure-blob-storage","file-not-found","file-storage"],"backgroundTag":"file-not-found","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}