LykosAI/StabilityMatrix · error · IOException
Path is not a junction point.
Error message
Path is not a junction point.
What it means
Junction.Delete throws IOException("Path is not a junction point.") when the given path exists but is a regular file, not a directory/junction. A junction delete only makes sense for a directory reparse point, so the library refuses to act on a file path. If the path doesn't exist at all, Delete silently returns.
Solutions
- Check the path type first and only call Junction.Delete on directories/junctions; delete plain files with File.Delete.
- Verify you are passing the junction (link) path, not the target directory path.
- If a file erroneously occupies the junction path, delete the file and re-create the junction.
- Use Junction.Exists or reparse-point inspection to confirm the path is a junction before deleting.
Example fix
// before
Junction.Delete(path); // throws if path is a file
// after
if (Directory.Exists(path)) {
Junction.Delete(path);
} else if (File.Exists(path)) {
File.Delete(path);
} Defensive patterns
Strategy: type-guard
Validate before calling
if (!Directory.Exists(junctionPoint)) return; // nothing to delete (or file handled separately)
Type guard
static bool IsDirectoryPath(string p) => Directory.Exists(p);
Try / catch
try { Junction.Delete(path); }
catch (IOException ex) when (ex.Message.Contains("not a junction")) { File.Delete(path); } Prevention
- Check Directory.Exists vs File.Exists before deleting.
- Pass the junction (link) path, never the target directory, to Junction.Delete.
- Inspect reparse points to confirm a path is a junction before cleanup.
When it happens
Trigger: Calling Junction.Delete(junctionPoint) where the path is an existing regular file (File.Exists true, Directory.Exists false) — e.g. the junction was replaced by a file, or the wrong path was passed to cleanup code.
Common situations: Cleanup logic that assumed everything at the path was a junction; a tool replaced the junction with a hardlink/file; path confusion between link path and target path; leftover files from partial uninstalls.
Related errors
- Failed to delete junction point
- Target path does not exist or is not a directory
- Directory already exists and overwrite parameter is false.
- Unable to delete junction point.
- Failed to delete junction point
AI-assisted analysis of LykosAI/StabilityMatrix@af93d6ef57 (2026-09-12).
Data as JSON: /api/errors/a278e5f524d89fc9.
Report an issue: GitHub.
Appendix: source
Thrown at StabilityMatrix.Core/ReparsePoints/Junction.cs:116
}
}
finally
{
Marshal.FreeHGlobal(inBuffer);
}
}
/// <summary>
/// Deletes a junction point at the specified source directory along with the directory itself.
/// Does nothing if the junction point does not exist.
/// </summary>
/// <param name="junctionPoint">The junction point path</param>
public static void Delete(string junctionPoint)
{
if (!Directory.Exists(junctionPoint))
{
if (File.Exists(junctionPoint))
throw new IOException("Path is not a junction point.");
return;
}
using var fileHandle = OpenReparsePoint(junctionPoint, Win32FileAccess.GenericWrite);
var reparseDataBuffer = new ReparseDataBuffer
{
ReparseTag = (uint) DeviceIoControlCode.ReparseTagMountPoint,
ReparseDataLength = 0,
PathBuffer = new byte[0x3ff0]
};
var inBufferSize = Marshal.SizeOf(reparseDataBuffer);
var inBuffer = Marshal.AllocHGlobal(inBufferSize);
try
{
Marshal.StructureToPtr(reparseDataBuffer, inBuffer, false);View on GitHub (pinned to af93d6ef57)