MicrosoftEdge / WebView2Feedback

Feedback and discussions about Microsoft Edge WebView2
https://aka.ms/webview2
453 stars 55 forks source link

[Problem/Bug]: Webview2 FileIO.writeTextAsync throws "The system cannot find the file specified 0x80070002" when writing on the same file multiple times asynchronous #4745

Open josephsobhy opened 3 months ago

josephsobhy commented 3 months ago

What happened?

Using the WinRT API Windows.Storage.FileIO.writeTextAsync from java script in webview2 throws "The system cannot find the file specified 0x80070002" even that the file exists.

Some times it throws "The process cannot access the file because it is being used by another process. (0x80070020)" which is expected but the 0x80070002 is not correct.

Also tested the same behaviour is webview1 and it never throws anything!.

let root = Windows.Storage.ApplicationData.current.localFolder;

root.createFileAsync("fileName", Windows.Storage.CreationCollisionOption.openIfExists).then((file) => {
       Windows.Storage.FileIO.writeTextAsync(file, "data 1")
       console.log('data 1 saved');
   })

  root.createFileAsync("fileName", Windows.Storage.CreationCollisionOption.openIfExists).then((file) => {
       Windows.Storage.FileIO.writeTextAsync(file, "data 2")
       console.log('data 2 saved');
   })

writeText issue

Importance

Important. My app's user experience is significantly compromised.

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

No response

SDK Version

No response

Framework

WinUI2/UWP

Operating System

Windows 10, Windows 11

OS Version

No response

Repro steps

let root = Windows.Storage.ApplicationData.current.localFolder;

root.createFileAsync("fileName", Windows.Storage.CreationCollisionOption.openIfExists).then((file) => {
       Windows.Storage.FileIO.writeTextAsync(file, "data 1")
       console.log('data 1 saved');
   })

  root.createFileAsync("fileName", Windows.Storage.CreationCollisionOption.openIfExists).then((file) => {
       Windows.Storage.FileIO.writeTextAsync(file, "data 2")
       console.log('data 2 saved');
   })

Repros in Edge Browser

No, issue does not reproduce in the corresponding Edge version

Regression

Don't know

Last working version (if regression)

No response

AB#54034963

champnic commented 2 months ago

Thanks for letting us know about this issue @josephsobhy - I've added it to our internal tracking.