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
563 stars 99 forks source link

File.Open doesn't set FileStream.Name #494

Open ghost opened 6 years ago

ghost commented 6 years ago

If I call File.Open the returned FileStream object has it's Name property set to '[Unknown]'. With the .NET variant of File.Open this property is set to the file path.

Yomodo commented 6 years ago

A possible workaround for this issue, here #438.

ghost commented 6 years ago

OK, sorry for not finding this before writing.

I've searched a bit through the .NET and AlphaFS code and I think this is caused by AlphaFS always creating the FileStream from handle and not from path. If the FileStream is created from handle the Name property is set to null (https://referencesource.microsoft.com/#mscorlib/system/io/filestream.cs,c49450a04f720cdd).

Maybe this can be worked around somehow?

alphaleonis commented 6 years ago

I think the only way to work around it is if we'd use reflection to set the _fileName field of the FileStream instance after creating it. It could be a viable option actually, since this is a quite annoying "bug". What do you think @Yomodo? (We would just need to create tests for this to ensure it doesn't break with new .NET versions, but I find it unlikely that they'd change this).

Yomodo commented 6 years ago

@alphaleonis Sounds like a plan!