{"record":{"id":"8eb65005263897f5","repo":"dotnet/machinelearning","slug":"directory-0-does-not-exist","errorCode":null,"errorMessage":"Directory \"{0}\" does not exist.","messagePattern":"Directory \"(.+?)\" does not exist\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.ML.ImageAnalytics/ImageLoader.cs","lineNumber":114,"sourceCode":"        /// <summary>\n        /// Initializes a new instance of <see cref=\"ImageLoadingTransformer\"/>.\n        /// </summary>\n        /// <param name=\"env\">The host environment.</param>\n        /// <param name=\"imageFolder\">Folder where to look for images.</param>\n        /// <param name=\"type\">Image type flag - true for ImageDataViewType or false for VectorDataViewType. Defaults to true i.e. ImageDataViewType if not specified.</param>\n        /// <param name=\"columns\">Names of input and output columns.</param>\n        internal ImageLoadingTransformer(IHostEnvironment env, string imageFolder = null, bool type = true, params (string outputColumnName, string inputColumnName)[] columns)\n            : base(Contracts.CheckRef(env, nameof(env)).Register(nameof(ImageLoadingTransformer)), columns)\n        {\n            // Throws ArgumentException if given imageFolder path is invalid. Note: imageFolder may be null or empty in this case.\n            if (String.IsNullOrEmpty(imageFolder))\n                ImageFolder = null;\n            else\n            {\n                if (Directory.Exists(imageFolder))\n                    ImageFolder = Path.GetFullPath(imageFolder);\n                else\n                    throw new ArgumentException(String.Format(\"Directory \\\"{0}\\\" does not exist.\", imageFolder));\n            }\n            _useImageType = type;\n        }\n\n        // Factory method for SignatureDataTransform.\n        internal static IDataTransform Create(IHostEnvironment env, Options options, IDataView data)\n        {\n            return new ImageLoadingTransformer(env, options.ImageFolder, options.Columns.Select(x => (x.Name, x.Source ?? x.Name)).ToArray())\n                .MakeDataTransform(data);\n        }\n\n        // Factory method for SignatureLoadModel.\n        private static ImageLoadingTransformer Create(IHostEnvironment env, ModelLoadContext ctx)\n        {\n            Contracts.CheckValue(env, nameof(env));\n            env.CheckValue(ctx, nameof(ctx));\n\n            ctx.CheckAtModel(GetVersionInfo());","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.ML.ImageAnalytics/ImageLoader.cs#L96-L132","documentation":"The ImageLoadingTransformer constructor validates the optional imageFolder argument before storing it. If the folder string is non-null but no directory exists at that path on disk, it throws an ArgumentException immediately at transform-construction time rather than during data loading.","triggerScenarios":"Passing a non-null imageFolder string to the ImageLoadingTransformer constructor (or the ImageLoadingEstimator options) where Directory.Exists(imageFolder) is false — typo'd path, relative path resolved from the wrong working directory, deleted/moved folder, or case/drive mismatch.","commonSituations":"Config files holding paths from another machine (Windows vs Linux path styles), running an app whose current working directory differs from where relative image paths were authored, deployment environments where the image folder was not copied.","solutions":["Correct the path to an existing directory (use an absolute path)","Call Directory.Exists(imageFolder) before constructing the transformer to fail fast with a clearer message","If the folder is optional in your pipeline, pass null instead of an empty/missing string","Ensure the directory is deployed/present in the runtime environment and the process has permissions to see it"],"exampleFix":"// before\nvar transformer = new ImageLoadingTransformer(env, \"images\", \"ImagePath\");\n// after\nstring imageFolder = Path.Combine(AppContext.BaseDirectory, \"images\");\nif (!Directory.Exists(imageFolder))\n    throw new DirectoryNotFoundException($\"Image folder missing: {imageFolder}\");\nvar transformer = new ImageLoadingTransformer(env, imageFolder, \"ImagePath\");","handlingStrategy":"validation","validationCode":"if (imageFolder != null && !Directory.Exists(imageFolder))\n    throw new DirectoryNotFoundException($\"Image folder does not exist: {imageFolder}\");","typeGuard":"bool IsValidImageFolder(string path) => path == null || (Directory.Exists(path) && (File.GetAttributes(path) & FileAttributes.Directory) != 0);","tryCatchPattern":"try\n{\n    var transformer = new ImageLoadingTransformer(env, imageFolder, nameColumn);\n}\ncatch (ArgumentException ex) when (ex.Message.Contains(\"does not exist\"))\n{\n    logger.LogError(ex, \"Configured image folder missing: {Folder}\", imageFolder);\n}","preventionTips":["Store absolute paths in configuration","Resolve relative paths against a known base directory, not the process CWD","Check Directory.Exists during app startup / health checks","Verify path handling when moving configs between Windows and Linux"],"tags":["csharp","machine-learning","images","filesystem","argument-validation"],"backgroundTag":"directory-not-found","analyzedSha":"7b76e69cf964daeca3f1377af6bc5543284d56c6","analyzedAt":"2026-09-11T12:35:38.930Z","contentChangedAt":"2026-09-11T12:35:38.930Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}