Deployed C# app using WebView2 cannot find the Runtime

Kurt Granroth 26 Reputation points
2021-06-29T17:26:11.743+00:00

I created a C# DLL based on .NET 4.6.1 that has a form containing an element of type Microsoft.Web.WebView2.WinForms.WebView2. It uses the latest (as of 6/28/21) release version of the SDK, pulled automatically by Nuget:

  <ItemGroup>
    <PackageReference Include="Microsoft.Web.WebView2">
      <Version>1.0.864.35</Version>
    </PackageReference>
  </ItemGroup>

This works like a charm when run directly from Visual Studio 17 as well as directly clicking on the executable in the Release or Debug folders.

My end users won't have any of that installed, though, so I am installing the WebView2 runtime via a WiX installer Custom Action. The app installer runs the MicrosoftEdgeWebview2Setup.exe bootstrap installer which is installing the runtime. I do see the 'Microsoft Edge WebView2 Runtime' version 91.0.864.59 installed in the Windows 'Apps & features' panel.

With all this, the installed app can no longer run the WebView2 component. It ignores the runtime entirely and when the code invokes the form containing WebView2, I see the following exception:

 Could not load file or assembly 'Microsoft.Web.WebView2.WinForms, Version=1.0.864.35, Culture=neutral, PublicKeyToken=2a8ab48044d2601e' or one of its dependencies. The system cannot find the file specified.

The exception is clearly referencing the SDK and not the runtime. Looking at the release notes for SDK 1.0.864.35 for runtime support, I see: "Minimum Runtime version to load: 86.0.616.0 or newer". I have 91.0.864.59 installed so that should work.

I have only limited experience developing in Windows and this is my first C# app anywhere, so I am likely missing something fundamental. In my flailing around, I did see a few references to the WebView2Loader.dll. It's not clear to me if that is only applicable to C++ apps or if it also has meaning for C# -- the vast majority of sample code and question and answers as of this date still focus heavily on C++. On the off chance that it matters for C#, I did copy that DLL to my release folder, but that did nothing.

To sum it up, how do I deploy a C# application using a WebView2 WinForm component so that it uses the Runtime rather than a Nuget-installed SDK?

Microsoft Edge
Microsoft Edge
A Microsoft cross-platform web browser that provides privacy, learning, and accessibility tools.
2,150 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,291 questions
{count} votes

Accepted answer
  1. Kelly Klein 81 Reputation points
    2021-07-08T16:09:34.793+00:00

    Kurt:

    I had this issue as well. The issue for me was that WebView2Loader.dll was no present in my release package. I copied that from {root]\packages\Microsoft.Web.WebView2.1.0.864.35\build\native\x64 to my .exe directory and it worked fine. Not sure why Visual Studio does not include this native dll.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful