Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PathTooLongException #9

Closed
jweyrich opened this issue Sep 10, 2015 · 1 comment
Closed

PathTooLongException #9

jweyrich opened this issue Sep 10, 2015 · 1 comment

Comments

@jweyrich
Copy link
Contributor

jweyrich commented Sep 10, 2015

When handling files that have a path length larger than 260 characters (Windows' MAX_PATH), the following exception is thrown:

[PathTooLongException]: The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

The .NET API does not support these long paths because of many reasons - See Long Paths in .NET - While the Windows API supports them, I believe it's nearly impossible to get them to work seamlessly and transparently. We could opt for the \\?\ prefix but it will have other impacts. Quoting the previously referenced article:

First about security, the ?\ prefix not only enables long paths; it causes the path to be passed to the file system with minimal modification by the Windows APIs. A consequence is that ?\ turns off file name normalization performed by Windows APIs, including removing trailing spaces, expanding ‘.’ and ‘..’, converting relative paths into full paths, and so on. The existence of FileIOPermissions in .NET means that we absolutely have to work with normalized paths, or risk exposing a security threat. So we knew that if we wanted to use the ?\ prefix as part of the long path solution, we’d need the ability to normalize these paths as expected.

Another concern is inconsistent behavior that would result by exposing long path support. Long paths with the ?\ prefix can be used in most of the file-related Windows APIs, but not all Windows APIs. For example, LoadLibrary, which maps a module into the address of the calling process, fails if the file name is longer than MAX_PATH. So this means MoveFile will let you move a DLL to a location such that its path is longer than 260 characters, but when you try to load the DLL, it would fail. There are similar examples throughout the Windows APIs; some workarounds exist, but they are on a case-by-case basis.

Another factor, which is considered more of a pain factor, is compatibility with other Windows-based applications and the Windows shell itself, which only work with paths shorter than MAX_PATH (note that the Vista shell attempts to soften this limit, briefly described below). This means that if .NET supports long paths, then we’d let you create files that you couldn’t access via Explorer or the command prompt.

Official documentation can be found in Naming Files, Paths, and Namespaces.

@jweyrich
Copy link
Contributor Author

jweyrich commented Sep 14, 2015

Attempt to fix the cause of PathTooLongExceptions - Fixes #9.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant