Typically, the single most common reason why recursive searches of hard disks fail is when certain directories require permissions that the calling code does not have.
Okay, unfortunately the classes in
do not use Unicode paths (where you prefix "\\?\" to the path). You can avoid using System.IO and instead P/Invoke the API directly and use the W versions of the functions (and then use Unicode paths).
Example article that does this:
.NET 2.0 Workaround for PathTooLongException
Although the article explains a different API, you will need to do something similar.
Alternatively, just skip files that exceed the max-path (but I reckon you will end up skipping too many files if you go that route). The hardcoded value for MaxPath in
is 260 (Windows ANSI filepath limit).