Jump to content
View in the app

A better way to browse. Learn more.

Tuts 4 You

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

C# .NET File.Open() strage behaviour

Featured Replies

Posted

Let's say I have a piece of code like this one:

private void RecursePath(DirectoryInfo Root)
{
if (Root.Exists)
{
//System.Threading.Thread.Sleep(15000);
FileInfo[] files = Root.GetFiles();
LastFile = "";
foreach (FileInfo fi in files)
{
try
{
LastFile = fi.FullName;
FileStream f = File.Open(LastFile, FileMode.Open);
f.Close();
//FileIO TestFile = new FileIO(LastFile, FileIO.FileIoMode.OpenExisting);
}
catch (Exception e)
{
PrintException(LastFile, e);
}
}

Yeah, it's a bit ugly sorry. The point is that I'm having some troubles trying to understand why File.Open() throws PathTooLongException with paths shorter than 248/260 bytes (I'm talking about 160 bytes or so). After attaching a native debugger to the running app I can see that CreateFileW is returning a valid handle and GetLastErr = ERROR_SUCCESS. WTF!?

Also, if use CreateFileW directly using NativeMethods (that's what this commented FileIO class does) the behaviour is exactly the same.

So the question is... anyone experienced similar problems? Or has any hint about where's the problem? I know this is not strictly related to reversing but I think is strange enough to share this X-File ;D

Thanks!

  • Author

Reply-to-myself. The problem was at LastFile = fi.FullName;

So only by accessing fi.FullName causes a PathTooLongException if FullName.Length > 260 and my code was showing LastFile.... bakayaro!! The funny thing is that in the MSDN doc says FullName can only throw SecurityException :blink:

Well, sorry about the noise :)

Create an account or sign in to comment

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.