alphaleonis / AlphaFS

AlphaFS is a .NET library providing more complete Win32 file system functionality to the .NET platform than the standard System.IO classes.
http://alphafs.alphaleonis.com/
MIT License
562 stars 99 forks source link

InvalidOperationException on Directory.EnumerateFileSystemEntries() #441

Closed CyberSinh closed 6 years ago

CyberSinh commented 6 years ago

Hi,

If I run these commands under PowerShell:

$path = "\\Ds216j\sauvegardes\Documents" # it's a shared folder on a Synology NAS
[Alphaleonis.Win32.Filesystem.Directory]::GetFileSystemEntryInfo($path)
[Alphaleonis.Win32.Filesystem.Directory]::EnumerateFileSystemEntries($path)

I get the following output:

1526105805067blob

As you can see, the target folder is well identified as a directory by AlphaFS. However, if I try to enumerate the contents of this folder, I get an error "the target directrory is a file, not a directory". Does anybody know why?

Thanks.

Yomodo commented 6 years ago

curious.. how about other unc/local paths? It think that the problem is not the path itself (\\Ds216j\sauvegardes\Documents), but the next folder or file that is returned by the enumeration. InvalidOperationException can point to a cyclic operation.

fwi98 commented 6 years ago

Ok . How can i see the "next folder or file returned" ? NAS logs or PC logs? Some folder are OK , other not. Thanks Regards

Yomodo commented 6 years ago

Hm.. the only way I can think of is using the VS debugger.

CyberSinh commented 6 years ago

Hi Yomodo. You will find attached the IntelliTrace file sent by the end user affected by this issue. Hope you will find it useful to diagnoose the issue. Thanks.

AlphaFS.itrace.zip

CyberSinh commented 6 years ago

Hi Yomodo. Was this iTrace file useful to you? Do you need more information?

Yomodo commented 6 years ago

Hi CyberSinh, thanks for this. Will analyze this in the next days.

Yomodo commented 6 years ago

Unfortunately, I only have access to VS 2015 Enterprise, loading the .Itrace throws a waring that I'm not able to view all the information.

However, the Exception is thrown here: https://github.com/alphaleonis/AlphaFS/blob/3e87fdec1d8cb15f2ecaf9f11ad6e1f62d17103d/AlphaFS/Filesystem/FindFileSystemEntryInfo.cs#L427

If you can place a breakpoint and run debug again, you should be able to see exactly what data win32FindData and regularPath contain. Hopefully this can tell us more.

CyberSinh commented 6 years ago

Hi Yomodo, You will find below a screenshot of Visual Studio 2017 with the iTrace log file opened: debug

You can view the win32FindData variable data.

Yomodo commented 6 years ago

I think the fix is simple; could you change this line: https://github.com/alphaleonis/AlphaFS/blob/3e87fdec1d8cb15f2ecaf9f11ad6e1f62d17103d/AlphaFS/Filesystem/FindFileSystemEntryInfo.cs#L303 to: if (null != handle && lastError != Win32Errors.NO_ERROR)

CyberSinh commented 6 years ago

Thank you very much Yomodo!

Yomodo commented 6 years ago

It works? Cool!

CyberSinh commented 6 years ago

I will propose a modified version of AlphaFS to the user concerned by this issue to check if the patch works. I'll keep you informed.

CyberSinh commented 6 years ago

I'm sorry but the user concerned has told me that the patch does not work. The same error always occurs. Here is the new IntelliTrace log: AlphaFS2.zip

Yomodo commented 6 years ago

I've made a new branch #441 based on the latest master. Could you test again with this?

CyberSinh commented 6 years ago

Everything works fine with this new branch. You can merge it. Thank you.

CyberSinh commented 6 years ago

Any timinig for a new maintenance nuget release?

Yomodo commented 6 years ago

Soon, I'll start preparing.