{"record":{"id":"826d2cecbaa7063a","repo":"microsoft/ailab","slug":"container-container-does-not-exist","errorCode":null,"errorMessage":"container {container} does not exist","messagePattern":"container (.+?) does not exist","errorType":"exception","errorClass":"ApplicationException","httpStatus":null,"severity":"error","filePath":"Sketch2Code/Sketch2Code.Core/Services/ObjectDetectionAppService.cs","lineNumber":292,"sourceCode":"            detail.OriginalImage = await this.GetFile(folderId, \"original.png\");\n            detail.PredictionImage = await this.GetFile(folderId, \"predicted.png\");\n            detail.PredictedObjects = await this.GetFile<IList<PredictedObject>>(folderId, \"results.json\");\n            var groupBox = await this.GetFile<GroupBox>(folderId, \"groups.json\");\n            detail.GroupBox = new List<GroupBox> { groupBox };\n\n            return detail;\n        }\n        public async Task<IList<CloudBlobContainer>> GetPredictionsAsync()\n        {\n            return await Task.Run(() => _cloudBlobClient.ListContainers().Where(l => l.Name != \"azure-webjobs-hosts\")\n                .OrderByDescending(c => c.Properties.LastModified).ToList());\n        }\n        public async Task<byte[]> GetFile(string container, string file)\n        {\n            var blobcontainer = _cloudBlobClient.GetContainerReference(container);\n            if (!await blobcontainer.ExistsAsync())\n            {\n                throw new ApplicationException($\"container {container} does not exist\");\n            }\n            var blob = blobcontainer.GetBlobReference(file);\n            if (!await blob.ExistsAsync())\n            {\n                throw new ApplicationException($\"file {file} does not exist in container {container}\");\n            }\n            using (var ms = new MemoryStream())\n            {\n                await blob.DownloadToStreamAsync(ms);\n                return ms.ToArray();\n            }\n        }\n        public async Task<T> GetFile<T>(string container, string file)\n        {\n            var data = await this.GetFile(container, file);\n            if (data == null) return default(T);\n            return JsonConvert.DeserializeObject<T>(Encoding.UTF8.GetString(data));\n        }","sourceCodeStart":274,"sourceCodeEnd":310,"githubUrl":"https://github.com/microsoft/ailab/blob/89fe2fc62081145ec5408d42059cbcb7c4a033c8/Sketch2Code/Sketch2Code.Core/Services/ObjectDetectionAppService.cs#L274-L310","documentation":"GetFile downloads a blob from an Azure Blob container and first verifies the container exists, throwing ApplicationException('container {container} does not exist') when the check fails. It then verifies the individual blob exists. This is the low-level file fetch used by GetPredictionAsync and other callers, so it surfaces whenever results are requested from a missing container.","triggerScenarios":"Calling GetFile(container, file) with a container name that has no matching container in the storage account — stale/typo folder id, wrong storage account, or deleted container — or invoking it as part of GetPredictionAsync/data/content flows against a nonexistent folder.","commonSituations":"Expired or cleaned-up prediction containers; mismatched storage connection string between save and read paths; user-supplied container id containing invalid characters or typos; reading results before the writing run completed.","solutions":["Confirm the container exists in the target storage account and that the connection string points to the same account","Re-run the analysis pipeline so results are saved before fetching files","Validate/normalize the container id from the request before calling GetFile","Check lifecycle management or cleanup jobs that might have removed the container","Handle ApplicationException in callers to return a clear 'results expired or not found' response"],"exampleFix":"// before\nvar bytes = await service.GetFile(folderId, \"original.png\");\n// after\nvar c = cloudBlobClient.GetContainerReference(folderId);\nif (!await c.ExistsAsync()) throw new ApplicationException($\"Prediction {folderId} expired; re-run the analysis\");\nvar bytes = await service.GetFile(folderId, \"original.png\");","handlingStrategy":"try-catch","validationCode":"var c = cloudBlobClient.GetContainerReference(container);\nif (!await c.ExistsAsync())\n    throw new ApplicationException($\"Container {container} does not exist\");","typeGuard":null,"tryCatchPattern":"try\n{\n    var bytes = await service.GetFile(container, file);\n}\ncatch (ApplicationException ex) when (ex.Message.StartsWith(\"container \"))\n{\n    logger.LogWarning(ex, \"Missing blob container {Container}\", container);\n    return NotFound($\"Results for {container} are unavailable.\");\n}","preventionTips":["Validate container ids from user input (format, existence) before fetching","Translate ApplicationException into meaningful HTTP responses","Verify connection string parity between write and read services","Check cleanup jobs and retention policies against expected result lifetime"],"tags":["csharp","azure-blob-storage","not-found","sketch2code"],"backgroundTag":"resource-not-found","analyzedSha":"89fe2fc62081145ec5408d42059cbcb7c4a033c8","analyzedAt":"2026-09-13T20:10:53.835Z","contentChangedAt":"2026-09-13T20:10:53.835Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}