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?