Search code examples
elevated-privilegeswebview2visual-studio-2022

How to fix msedgewebview2 error in VS2022 when admin?


I have installed the relatively fresh Visual Studio 2022 on a Windows installation. The work I do often requires administrative privileges (local IIS). To do this I have two users, one 'normal' account that is logged in to Windows and one administrator account. When starting VS2022 with the administrator account, an error keeps coming. It happens especially during debugging and it reads as follows:

Microsoft Edge can't read and write to its data directory:

C:\Users\<administrator_user>\AppData\Local\Temp\VSWebView2Cache\<guid>\EBWebView

What appears to happen is that Microsoft Edge WebView2 (msedgewebview2.exe) is running as the user that is logged in to Windows, while trying to write temporary files for the administrator user where it does not (and should not) have write or read access.

Here we can see the process details that says the application user is the logged in user and not the administrator: enter image description here

Does anyone know how to fix this issue?

The error happen even when I run debugging on a .net 5 console application. In that particular situation I don't see why it needs to run anything in a WebView instance, but apparently some background process is running something anyway. Is this something that can be turned off?


Solution

  • My best solution so far is to create a shared folder.

    I decided to make C:\Users\<administrator_user>\AppData\Local\Temp\VSWebView2Cache\ shared. The "VS" prefix indicates that this is a Visual Studio-specific folder, and I think it is acceptable that my normal user can have access to that folder as it seems to contain temporary Visual Studio files.

    To do so I logged in to Windows with the administrator account. I navigated to the folder and made it a shared folder. I added my no-admin user with "Read/Write" privileges. I then tested by logging out of the admin account and into my no-admin account. There I first tried the full path in File Explorer and was granted access to the folder. I then tested with VS2022 and during debugging no error box appeared and files were generated in the folder.

    If anyone finds a better approach, I'd really like to hear about it. Also if you have knowledge to why this approach is either good or bad, that would be highly appreciated as well.