-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Closed
dotnet/android
#3515Description
Hello!
I got exception in my code when i try to copy files using FileStream with FileShare parameter.
Steps to Reproduce
- create Program.cs file
using System;
using System.IO;
namespace FileCopy
{
class Program
{
static void Main(string[] args)
{
try
{
File.WriteAllText("source.txt", "text");
var fileStream = new FileStream("source.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite, 2048, FileOptions.DeleteOnClose);
File.Copy(fileStream.Name, "target.txt", true);
}
catch (Exception e)
{
File.WriteAllText("error.txt", e.Message + Environment.NewLine + e.StackTrace);
}
}
}
}
- run build command
mcs -out:Test.exe Program.cs
- execute
mono Test.exe
Current Behavior
got file error.txt with error & stack trace
IOException: Sharing violation on path .../source.txt
Expected Behavior
got file target.txt with "text" content.
file source.txt will be removed, because used FileOptions.DeleteOnClose parameter
[ ] macOS
[x] Linux
[ ] Windows