question

KurtGranroth-9502 avatar image
0 Votes"
KurtGranroth-9502 asked KurtGranroth-9502 commented

Deployed C# app using WebView2 cannot find the Runtime

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?

dotnet-csharpms-edge
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@TimonYang-MSFT
I agree that I'm missing something, but it's precisely that "some information" in "some configuration files" that I'm looking for. I disagree that this isn't a programming problem, though -- I am doing something in my app development which is problematic and I don't know if it's missed code, incorrect VS settings, incorrect Forms usage, or what else.

All software must eventually be deployed, so presumably I am not the first person to try and deploy a C# app that uses WebView2!

I have posted this question to the github issues page, as well, but answers to questions on that site are few and far between. I posting here to hopefully get an answer from another developer that has done exactly what I need to do.

1 Vote 1 ·

@KurtGranroth-9502
My thought is that it may be necessary to add some information in some configuration files, but I am not sure. I usually use it in my programs through its nuget package.
Since this is not a programming problem, I think it might be more appropriate to ask questions in its GitHub repository.

0 Votes 0 ·

1 Answer

KellyKlein-6143 avatar image
1 Vote"
KellyKlein-6143 answered KurtGranroth-9502 commented

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Kelly:

Thank you! Combining your answer with one I got on another site (the Github WebView2 Feedback site), I was able to come up with a fully working solution.

You are 100% correct that the WebView2Loader.dll file is necessary in the .exe directory. As mentioned in my question, I had tried that and it had done nothing for me. What I was missing was that IN ADDITION to the WebView2Loader.dll file, I also needed to copy over these three DLLs from the SDK into my .exe directory:

Microsoft.Web.WebView2.Core.dll
Microsoft.Web.WebView2.Wpf.dll
Microsoft.Web.WebView2.WinForms.dll

All four SDK files are necessary in order for the app to use the Runtime.

0 Votes 0 ·