Unhandled Exception while disposing ExtFileStream
Hi,
I get an unhandled exception during disposing the ExtFileStream. The target framework of my application is .NET 7.
I do simple copy operations of large files (up to 2 GB) from my NTFS-Disk to a Micro-SD (Ext4).
Source
ExtDisk disk = ExtDisk.Open(diskNumber);
ExtFileSystem fileSystem = ExtFileSystem.Open(disk, disk.Partitions[0]);
byte[] buffer = File.ReadAllBytes(sourcePath);
using ExtFileStream stream = fileSystem.OpenFile(destinationPath, FileMode.Create, FileAccess.Write);
stream.Write(buffer, 0, buffer.Length);
stream.Close();
The operation is successful but after the call of Dispose via the using-operator or calling Dispose I get the following exception:

Is this the default behavior? Any idea for a workaround?
~Best Regards
Compile as release mode and try again.
Same result in release mode:

Then it could be heap corruption.
Do you have any idea how to check if the heap is corrupted and/or how to fix it? I‘m not familar with problems like this.
Just a quick glimpse the screen shot you attached, it seems you are using x64 release, as you can see ext4_write takes uint64 as input, however extfilestream passes int32.
You said you were copying large file (2gb). This may be the reason.
Try x86 mode, or use smaller file
Thank you for your tips.
I found out the error only occurs when ExtFileStream.Close() is called shortly before disposing.
If I skip closing the stream before disposing, it works. But on the other hand I get a memory leak, the RAM is not released properly.
Is disposing not closing the stream at all? I think this would be the expected behavior.
Maybe we can improve the whole thing, Dispose should better not throw an error exception if the stream is closed.
ExtFileStream inherits . Net Stream class and override close. https://github.com/nickdu088/SharpExt4/blob/main/SharpExt4/ExtFileStream.h#L37
It should be all handled by Stream base class.