File.Delete() throw "owner died" in Xamarin

Viewed 69

Generally, file deletion can be performed correctly on most Android phones However, when I run this line of code on "Huawei art-al00x (Android 10.0 - API 29)", the operation throws an exception "owner died"

I can create files and write data, but I can't delete files

I've never been in this situation before

After Google searched, there is still no result

After the second test, I found that if I checked the file in the file manager, I could delete it smoothly, while if I didn't check the file, it would throw an exception

The Code:

string path = "Want Save Path";
byte[] buffer = new uint8_t[73790];
using (BinaryWriter BW = new BinaryWriter(new FileStream(path, FileMode.Create)))
{
    BW.Write(buffer, 0, (int)exer.Size);
    BW.Flush();
    BW.Close();
    Console.WriteLine("USM:Save Image Data Success");
}

StackTrace:

at System.IO.FileSystem.DeleteFile (System.String fullPath) [0x00065]
in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.IO.FileSystem/src/System/IO/FileSystem.Unix.cs:215
at System.IO.File.Delete (System.String path) [0x0000e]
in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.IO.FileSystem/src/System/IO/File.cs:107
at DebugTest.MyView.MainPage_OperateView.TTTFrame_Click () [0x00014]
in G:\VS2019 Projects\DebugTest\DebugTest\DebugTest\MyView\MainPage_OperateView.xaml.cs:263

0 Answers
Related