Visual Studio 2022 WebView2 bugs

I’ve been tearing my hair out for the last couple of days – trying to work out why previous perfectly good apps completely crashed WebView2 using Visual Studio 2022!

Visual Studio 2022 smoothly allows WebView2 to be installed and loaded into the toolbox. But using it kept failing on:
 ‘WebView21_CoreWebView2InitializationCompleted(sender As Object, e As Microsoft.Web.WebView2.Core.CoreWebView2InitializationCompletedEventArgs) Handles WebView21.CoreWebView2InitializationCompleted’
Returning e.IsSuccess = False

With the message:
{“Couldn’t find a compatible Webview2 Runtime installation to host WebViews.”}

I repeatedly tried repairing & reinstalling Webview2 and Microsoft Edge WebView2 Runtime, trying many different versions – none worked.

Microsoft documentation for WebView2 suggests uninstalling Microsoft Edge – even though they also say WebView2 is completely separate (to avoid updates needing to be synchronised)

Yet Microsoft Edge can no longer be removed because it is now an integral part of Windows! But ‘repairing’ it didn’t help either.

My previously saved and packaged ‘release’ software from Visual Studio 2022 ALL still worked as ‘stand-alone’ apps, but copying working runtime files from these into newly created releases still failed.

Eventually I gave up with Visual Studio 2022 and went back to an app created with Visual Studio 2019 – and voila it worked fine, even allowing debugging! This wasn’t really going to solve my problem because all my latest apps use .net 8 which can’t easily be ported back to .net 4.8 Frameword

Nevertheless as an experiment I created a new app to test WebView2 using Visual Studio 2019 with .Net Framework 4.8 and that also worked first time! (after the usual fiddle to get WebView2 to appear in my toolbox)

Yet anything I tried creating in Visual Studio 2022 with .Net 6, 7 or 8 failed miserably.

In creating a new app in Visual Studio 2019 it wanted to use the default directory of:
c:/users/myname/source/repos/appname.

I changed it to where I save all my apps:
d:/myname/documents/VisualStudio2024 and it still worked.

Finally, I thought I would see what happened if I used Visual Studio 2022 to create and save a simple WebView2 app in:
c:/users/myname/source/repos/appname

And guess what – it worked first time!!!

In summary, if you are having problems with Visual Studio 2022 running WebView2 – make sure you work from your user /source/repos folder.

If only I could charge Microsoft for some of my time wasted finding work-arounds for their bugs!
Anyway, hope this sorry tale helps a few other programmers struggling with the same problem.

Comments are closed.