MicrosoftEdge / MicrosoftEdge/WebView2Feedback

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

Open
#4,745 1 comment 0 reactions 1 assignee View on GitHub

@champnic is already working on this.

Since Sep 20, 2024.

bug tracked
Dominant language
PowerShell
Stars
526
Forks
67
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.