{"record":{"id":"b97001f7314827a3","repo":"microsoft/ailab","slug":"container-folderid-does-not-exist","errorCode":null,"errorMessage":"Container {folderId} does not exist","messagePattern":"Container (.+?) does not exist","errorType":"exception","errorClass":"DirectoryNotFoundException","httpStatus":null,"severity":"error","filePath":"Sketch2Code/Sketch2Code.Core/Services/ObjectDetectionAppService.cs","lineNumber":268,"sourceCode":"            var permission = new BlobContainerPermissions();\n            permission.PublicAccess = BlobContainerPublicAccessType.Blob;\n            await theContainer.SetPermissionsAsync(permission);\n            if (relativePath != rootContainerPath)\n            {\n                fileName = Path.Combine(relativePath, fileName);\n            }\n            var blob = theContainer.GetBlockBlobReference(fileName);\n            await blob.UploadTextAsync(html);\n        }\n        public async Task<PredictionDetail> GetPredictionAsync(string folderId)\n        {\n            if (String.IsNullOrWhiteSpace(folderId))\n                throw new ArgumentNullException(\"folderId\");\n\n            var blobContainer = _cloudBlobClient.GetContainerReference(folderId);\n            bool exists = await blobContainer.ExistsAsync();\n            if (!exists)\n                throw new DirectoryNotFoundException($\"Container {folderId} does not exist\");\n\n            var groupsBlob = blobContainer.GetBlockBlobReference(\"groups.json\");\n\n            var detail = new PredictionDetail();\n\n            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        }","sourceCodeStart":250,"sourceCodeEnd":286,"githubUrl":"https://github.com/microsoft/ailab/blob/89fe2fc62081145ec5408d42059cbcb7c4a033c8/Sketch2Code/Sketch2Code.Core/Services/ObjectDetectionAppService.cs#L250-L286","documentation":"GetPredictionAsync reads a previously saved prediction (groups.json, original.png, etc.) from an Azure Blob container named after the folderId. It first checks whether the container exists and throws DirectoryNotFoundException('Container {folderId} does not exist') when it does not, since results for an unknown folder id cannot be fetched.","triggerScenarios":"Calling GetPredictionAsync(folderId) with a folderId for which no blob container was ever created — e.g. a stale id, a typo, or querying before the image-processing Run completed and saved the results.","commonSituations":"Sharing a prediction URL whose blob container was deleted or expired (storage lifecycle/cleanup rules); typos in the folder id taken from a URL; hitting the API before the Sketch2Code run finished writing results; using a different storage account than the one that stored the results.","solutions":["Verify the folderId corresponds to an existing container in the storage account (check with Azure Storage Explorer or az storage container list)","Re-run the image analysis to generate results before calling GetPredictionAsync","Confirm the service is pointed at the same storage account/connection string that saved the results","Check container cleanup/lifecycle policies that may have deleted old prediction containers","Validate the folderId from the request (no truncation/typos) before calling"],"exampleFix":"// before\nvar detail = await service.GetPredictionAsync(id);\n// after\nvar container = cloudBlobClient.GetContainerReference(id);\nif (!await container.ExistsAsync()) {\n    throw new ApplicationException($\"Prediction {id} not found or expired; run the analysis again\");\n}\nvar detail = await service.GetPredictionAsync(id);","handlingStrategy":"try-catch","validationCode":"var container = cloudBlobClient.GetContainerReference(folderId);\nif (!await container.ExistsAsync())\n    throw new ApplicationException($\"Prediction {folderId} not found or expired\");","typeGuard":null,"tryCatchPattern":"try\n{\n    var detail = await service.GetPredictionAsync(folderId);\n}\ncatch (DirectoryNotFoundException ex)\n{\n    logger.LogWarning(ex, \"Prediction container missing for {FolderId}\", folderId);\n    return NotFound($\"Prediction {folderId} not found or expired; re-run the analysis.\");\n}","preventionTips":["Map DirectoryNotFoundException to HTTP 404/410 in the API layer","Re-check folder ids from URLs before lookup","Account for storage lifecycle cleanup when retaining results","Ensure the same storage account is used for save and read paths"],"tags":["csharp","azure-blob-storage","not-found","sketch2code"],"backgroundTag":"directory-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"}