.netcore linux UnauthorizedAccessException Access to the path "/xxx" is denied

-1

Cannot write to file using netcore 2.1 / linux. Have confirmed my test app do have the write/read/delete privilege of the destination folder. but always get UnauthorizedAccessException exception.

Below is the sample code.

    var keyfile = "/mnt/temp/1.txt";
    System.IO.File.Create(keyfile).Dispose(); // this will create new file .     
    var fileMode = System.IO.FileMode.Append;
    var fileAccess = System.IO.FileAccess.Write;
    var fileShare = System.IO.FileShare.ReadWrite;
    using ( var fs = new System.IO.FileStream(keyfile,fileMode,fileAccess,fileShare))
    using (var sw = new System.IO.StreamWriter(fs))
    {
        //Failed with  exception
    //  System.UnauthorizedAccessException
    // HResult=0x80070005
    // Message=Access to the path '/mnt/temp/1.txt' is denied.
    // Source=System.Private.CoreLib
    // StackTrace:
    // at System.IO.FileStream.WriteNative(ReadOnlySpan`1 source)
    // at System.IO.FileStream.FlushWriteBuffer()
        sw.WriteLine("some text...");
    }
c#
linux
asked on Stack Overflow Jul 9, 2020 by chen dev

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0