MonoGame/MonoGame · error · ContentLoadException

The directory was not found.

Error message

The directory was not found.

What it means

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.

Source

Thrown at MonoGame.Framework/Content/ContentManager.cs:411

#endif
                stream = TitleContainer.OpenStream(assetPath);
#if ANDROID
                // Read the asset into memory in one go. This results in a ~50% reduction
                // in load times on Android due to slow Android asset streams.
                MemoryStream memStream = new MemoryStream();
                stream.CopyTo(memStream);
                memStream.Seek(0, SeekOrigin.Begin);
                stream.Close();
                stream = memStream;
#endif
			}
			catch (FileNotFoundException fileNotFound)
			{
				throw new ContentLoadException("The content file was not found.", fileNotFound);
			}
			catch (DirectoryNotFoundException directoryNotFound)
			{
				throw new ContentLoadException("The directory was not found.", directoryNotFound);
			}
			catch (Exception exception)
			{
				throw new ContentLoadException("Opening stream error.", exception);
			}

			return stream;
		}

        /// <summary />
		protected T ReadAsset<T>(string assetName, Action<IDisposable> recordDisposableObject)
		{
			if (string.IsNullOrEmpty(assetName))
			{
				throw new ArgumentNullException("assetName");
			}
			if (disposed)
			{

View on GitHub (pinned to 1d71bbd0ff)

Solutions

  1. Confirm the full directory <RootDirectory>/<assetName folder> exists in the runtime output.
  2. Make sure the content build preserves subfolder structure into the output Content directory.
  3. Validate RootDirectory is correct (relative to the working directory / title location).
  4. Inspect InnerException.Message for the path the OS could not find.
  5. On packaged/mobile builds, verify the folder is listed as an AndroidAsset / bundled resource.
  6. Re-run MGCB and confirm the directory layout in the build output.

Example fix

// before
Content.RootDirectory = "Content";
Content.Load<SoundEffect>("Audio/Explode"); // DirectoryNotFoundException: Audio missing
// after: ensure Audio/ ships under output Content/Audio/Explode.xnb, or fix RootDirectory
Defensive patterns

Strategy: try-catch

Validate before calling

string dir = Path.GetDirectoryName(Path.Combine(Content.RootDirectory, assetName));
if (!Directory.Exists(dir)) throw new DirectoryNotFoundException("Missing dir: " + dir);
var asset = Content.Load<T>(assetName);

Try / catch

try { return Content.Load<T>(assetName); }
catch (ContentLoadException ex) when (ex.InnerException is DirectoryNotFoundException)
{ logger.Error($"Missing content directory for {assetName}"); throw; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of MonoGame/MonoGame@1d71bbd0ff (2026-08-13). Data as JSON: /api/errors/ebefd88e2f6b6db7. Report an issue: GitHub.