{"record":{"id":"ebefd88e2f6b6db7","repo":"MonoGame/MonoGame","slug":"the-directory-was-not-found","errorCode":null,"errorMessage":"The directory was not found.","messagePattern":"The directory was not found\\.","errorType":"exception","errorClass":"ContentLoadException","httpStatus":null,"severity":"error","filePath":"MonoGame.Framework/Content/ContentManager.cs","lineNumber":411,"sourceCode":"#endif\n                stream = TitleContainer.OpenStream(assetPath);\n#if ANDROID\n                // Read the asset into memory in one go. This results in a ~50% reduction\n                // in load times on Android due to slow Android asset streams.\n                MemoryStream memStream = new MemoryStream();\n                stream.CopyTo(memStream);\n                memStream.Seek(0, SeekOrigin.Begin);\n                stream.Close();\n                stream = memStream;\n#endif\n\t\t\t}\n\t\t\tcatch (FileNotFoundException fileNotFound)\n\t\t\t{\n\t\t\t\tthrow new ContentLoadException(\"The content file was not found.\", fileNotFound);\n\t\t\t}\n\t\t\tcatch (DirectoryNotFoundException directoryNotFound)\n\t\t\t{\n\t\t\t\tthrow new ContentLoadException(\"The directory was not found.\", directoryNotFound);\n\t\t\t}\n\t\t\tcatch (Exception exception)\n\t\t\t{\n\t\t\t\tthrow new ContentLoadException(\"Opening stream error.\", exception);\n\t\t\t}\n\n\t\t\treturn stream;\n\t\t}\n\n        /// <summary />\n\t\tprotected T ReadAsset<T>(string assetName, Action<IDisposable> recordDisposableObject)\n\t\t{\n\t\t\tif (string.IsNullOrEmpty(assetName))\n\t\t\t{\n\t\t\t\tthrow new ArgumentNullException(\"assetName\");\n\t\t\t}\n\t\t\tif (disposed)\n\t\t\t{","sourceCodeStart":393,"sourceCodeEnd":429,"githubUrl":"https://github.com/MonoGame/MonoGame/blob/1d71bbd0ff4071a03caa583aa3bc56b85924a819/MonoGame.Framework/Content/ContentManager.cs#L393-L429","documentation":"Wrapped DirectoryNotFoundException from ContentManager.OpenStream. The parent directory of the requested <RootDirectory>/<assetName>.xnb does not exist, so the open fails before reaching the file. Rethrown as ContentLoadException with the original DirectoryNotFoundException as InnerException; the message itself does not name the missing directory.","triggerScenarios":"Loading an asset whose intermediate folder is absent (e.g. Content.Load(\"Fonts/UI\") when the Fonts directory was never created in the output), or setting RootDirectory to a path that itself is missing. Distinguished from file-not-found by which OS exception the title container raised.","commonSituations":"Content subfolders not copied to the deployment output, RootDirectory pointing at a stale/renamed folder, packaging step that flattens directories, or a path-joining bug where backslashes/forward slashes produce a nonexistent segment on a given platform.","solutions":["Confirm the full directory <RootDirectory>/<assetName folder> exists in the runtime output.","Make sure the content build preserves subfolder structure into the output Content directory.","Validate RootDirectory is correct (relative to the working directory / title location).","Inspect InnerException.Message for the path the OS could not find.","On packaged/mobile builds, verify the folder is listed as an AndroidAsset / bundled resource.","Re-run MGCB and confirm the directory layout in the build output."],"exampleFix":"// before\nContent.RootDirectory = \"Content\";\nContent.Load<SoundEffect>(\"Audio/Explode\"); // DirectoryNotFoundException: Audio missing\n// after: ensure Audio/ ships under output Content/Audio/Explode.xnb, or fix RootDirectory","handlingStrategy":"try-catch","validationCode":"string dir = Path.GetDirectoryName(Path.Combine(Content.RootDirectory, assetName));\nif (!Directory.Exists(dir)) throw new DirectoryNotFoundException(\"Missing dir: \" + dir);\nvar asset = Content.Load<T>(assetName);","typeGuard":null,"tryCatchPattern":"try { return Content.Load<T>(assetName); }\ncatch (ContentLoadException ex) when (ex.InnerException is DirectoryNotFoundException)\n{ logger.Error($\"Missing content directory for {assetName}\"); throw; }","preventionTips":["Verify content subfolder structure is preserved in build output.","Validate RootDirectory before load loops.","On mobile, declare asset folders correctly in the manifest/package.","Inspect the InnerException for the missing directory path.","Add a CI check that all referenced asset folders exist in the output."],"tags":["content","xnb","content-loading","directory","filesystem"],"backgroundTag":null,"analyzedSha":"1d71bbd0ff4071a03caa583aa3bc56b85924a819","analyzedAt":"2026-08-13T17:10:33.625Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}