Skip to content

[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

Description

@josephsobhy

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingtrackedWe are tracking this work internally.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions