Skip to content

How to Embed WebView2 Runtimes in .NET Framework Class Library With Fody Weavers #2636

Description

@protegesolutions

I've read the two or three (closed) posts that mention the need to do this but they don't seem to resolve the issue.

We have a class library (consumed by third-party apps not under our control, and obviously a single file with embedded references) that previously used the WebBrowser control. That was a very simple, easy to use and deploy control that is now past its prime. But trying to employ WebView2 has been quite a struggle. Now we have it working but we can't get the runtimes to be included in the dll. (We would have settled for the WebView control but that has issues running under Admin rights, bizarrely.)

The library is .NET 4.6.2 (for as much backward compatibility in the .NET Framework as possible). We use Fody Weavers to include RestSharp, NLog, etc and have now added Microsoft.Web.WebView2.Core, Microsoft.Web.WebView2.WinForms and Microsoft.Web.WebView2.Wpf.

We also have the Costura directive UseRuntimeReferencePaths='true' which I believe is required for .NET Framework projects.

But when I run the app test form - which consumes the library - I get a path error:

The path is not of a legal form.
at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
at System.IO.Path.InternalGetDirectoryName(String path)
at Microsoft.Web.WebView2.Core.CoreWebView2Environment.LoadWebView2LoaderDll()
at Microsoft.Web.WebView2.Core.CoreWebView2Environment.<CreateAsync>d__3.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Microsoft.Web.WebView2.WinForms.WebView2.<InitCoreWebView2Async>d__23.MoveNext()

I've tried a few things to ensure that the runtimes are included such as embedding them as resources, to no avail.

This is a deal breaker for us if we can't get this working; we MUST have everything included in a single library/dll. So my question is, has anyone managed to do this? (Praying that the answer is, "Sure! Just do this ...".

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions