LykosAI/StabilityMatrix · error · DirectoryNotFoundException
Source directory not found
Error message
Source directory not found: {dir.FullName} What it means
Utilities.CopyDirectory recursively copies a directory tree. It first wraps sourceDir in a DirectoryInfo and throws DirectoryNotFoundException when the source does not exist, so the copy never starts on a bogus root. The message includes the resolved full path for diagnosis.
Solutions
- Verify Directory.Exists(sourceDir) before calling CopyDirectory
- Correct the configured/source path (log the full resolved path)
- Create the source directory first if it is expected to be initialized elsewhere
- Catch DirectoryNotFoundException and show a user-facing 'source folder missing' message
Example fix
// before
Utilities.CopyDirectory(srcDir, dstDir);
// after
if (!Directory.Exists(srcDir))
throw new DirectoryNotFoundException($"Source missing: {srcDir}");
Utilities.CopyDirectory(srcDir, dstDir); Defensive patterns
Strategy: validation
Validate before calling
if (!Directory.Exists(sourceDir))
throw new DirectoryNotFoundException($"Source directory not found: {Path.GetFullPath(sourceDir)}"); Type guard
static bool IsExistingDir(string? p) => !string.IsNullOrWhiteSpace(p) && Directory.Exists(p);
Try / catch
try { Utilities.CopyDirectory(src, dst, true); }
catch (DirectoryNotFoundException ex) { MessageBox.Show($"Source folder missing: {ex.Message}"); } Prevention
- Validate configured source paths at startup
- Resolve and log full paths before copying
- Create source directories during setup/init flows
- Guard against unmounted drives/network shares before bulk copies
When it happens
Trigger: Calling CopyDirectory(sourceDir, destDir, ...) where sourceDir does not exist — unmounted drive, wrong base path, or directory deleted before the copy.
Common situations: Copying shared-model folders whose location was moved; backup/restore scripts running before the source was created; misconfigured settings pointing at a nonexistent directory.
Related errors
- Directory not found
- Source file does not exist
- Could not move file to
- Service type is not assignable to
- Service of type is not registered for
AI-assisted analysis of LykosAI/StabilityMatrix@af93d6ef57 (2026-09-12).
Data as JSON: /api/errors/ddbaabaf0ddbbf33.
Report an issue: GitHub.
Appendix: source
Thrown at StabilityMatrix.Core/Helper/Utilities.cs:31
var version = assembly.GetName().Version;
return version == null
? "(Unknown)"
: $"{version.Major}.{version.Minor}.{version.Build}.{version.Revision}";
}
public static void CopyDirectory(
string sourceDir,
string destinationDir,
bool recursive,
bool includeReparsePoints = false
)
{
// Get information about the source directory
var dir = new DirectoryInfo(sourceDir);
// Check if the source directory exists
if (!dir.Exists)
throw new DirectoryNotFoundException($"Source directory not found: {dir.FullName}");
// Cache directories before we start copying
var dirs = includeReparsePoints
? dir.GetDirectories()
: dir.GetDirectories().Where(d => !d.Attributes.HasFlag(FileAttributes.ReparsePoint));
// Create the destination directory
Directory.CreateDirectory(destinationDir);
// Get the files in the source directory and copy to the destination directory
foreach (var file in dir.GetFiles())
{
var targetFilePath = Path.Combine(destinationDir, file.Name);
if (file.FullName == targetFilePath)
continue;
file.CopyTo(targetFilePath, true);
}
View on GitHub (pinned to af93d6ef57)