1
using System;
using System.Windows.Forms;


namespace Test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
             Load += Form1_Load;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.webView21.Source = new Uri("https://www.google.com");
        }
    }
}

I am a student just starting to learn C#. If you simply write the code as above and publish it with (Clickonce) publish, the webview will work normally. However, if you make it as an msi file, the webview does not work. Can you help me with what needs to be done?

davmos
  • 9,324
  • 4
  • 40
  • 43
sophista
  • 13
  • 3

1 Answers1

0

A common cause is the WebView2Loader.dll not being included.

Sometimes it needs to be manually included.

See Distribute your app and the WebView2 Runtime - Files to ship with the app

Also see these discussions of the issue...

Deployed C# app using WebView2 cannot find the Runtime

WebView2Loader.dll is left out when publishing

WebView2Loader.dll is missing from the Installer Folder

WebView2 works in debug but not when published with ClickOnce

davmos
  • 9,324
  • 4
  • 40
  • 43
  • Thank you for your response. I have learned a lot from you. The problem has been solved, but a new problem has arisen. It seems that WebView2 cannot operate because it does not have permission to create a new folder in the program files folder. However, I do not have the ability to solve this problem. Is there an easier way to solve this? – sophista Apr 05 '23 at 05:19
  • Is it failing when trying to create the user data folder (UDF)? They say in most cases you should [specify a custom UDF location](https://learn.microsoft.com/en-us/microsoft-edge/webview2/concepts/user-data-folder?tabs=dotnet#tabpanel_2_dotnet). – davmos Apr 05 '23 at 09:00
  • Is the UDF you mentioned referring to C:\USER – sophista Apr 05 '23 at 16:07
  • If you don't supply a custom location then it will default to the Program Files folder, which you don't want. The recommended location appears to be the user's application data folder which you can get programmatically with `Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)` see [here](https://stackoverflow.com/questions/867485/c-sharp-getting-the-path-of-appdata) – davmos Apr 05 '23 at 16:25
  • Thank you for your response. The above explanation seems a little complicated to me, so I set the default installation folder to the c:\myapp folder and installed it, and the program works. Are there any differences between doing what you described and the way I do it? – sophista Apr 07 '23 at 13:05
  • Your way, the UDF location will always be c:\myapp. You just need to consider if different users will log on & use your app on the same machine, then they may be able to see another user's data. If you create the file using the code in my previous comment then each user will get their own UDF created in their own folders e.g. C:\Users\davmos\AppData\Roaming – davmos Apr 07 '23 at 20:03
  • thanks a lot. I have learned a lot from you. – sophista Apr 14 '23 at 00:33