MicrosoftEdge / MicrosoftEdge/WebView2Feedback

WebView2 in a DLL with Blazor doesn't load static assets

Open
#1,797 5 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug feature request
Dominant language
PowerShell
Stars
526
Forks
67
PR merge metrics
No merged PRs in 30d

Description

Description
This is a follow on from https://github.com/MicrosoftEdge/WebView2Feedback/issues/730. It concerns Blazor Hybrid apps but since the underlying control is webview2 I have raised it here. I have created a boilerplate Blazor server from visual studio, taken the content into a razor control library, wrapped that around in a win forms application and displaying it using Webview2 in WinForms.

So:
Razor Class Library + WinForms app = Working Hybrid Blazor App. (app calls razor class library). All good so far.

Now the next thing i need to do is move the webview2 into a class library (as I want to load this library in MS Office VSTO). I created a class library, added a win form and docked the webview2 into the WinForm. I create a separate WinForm project to load the class library.

So now i have:
Razor Class Library (same as above) + Class Library (webview2 docked in a WinForm) + Windows App (loads the class library).

The whole thing works i.e. the website loads into the webview2 but there are no static assets (in this case css etc.) so the site works but it devoid of CSS. It seems that putting the WebView2 into a DLL means that some setup needed for the loading of static assets from the Razor Class Library occurs.

When i bring up the webview2 debugging, I can see that it simply cannot find the assets (screenshots attached).

To Summarize
WinForms App + Razor Class Library = Working Hybrid app with all assets loaded.
WinForms App loading class library with DLL in WinForms + Razor class library = working hybrid app but no assets.

I have created a repository to demonstrate this to make it easier to follow:
https://github.com/Waahse/BlazorHybridTest

If you set the startup project as SampleWinformsApp it works perfectly, if you set the startup project as SampleWinformsLibrary Loader it works without assets. Both load the same Razor Class library the only difference is one is via a DLL.

Version
Framework: .net 6 preview
SDK: WebView2.core version 1.0.705.50, WebView2.Winforms version 1.0.705.50,
OS: Windows 10

Screenshots
Output showing lack of assets loading
SampleWinformsLibraryLoaderOutput

Output showing assets loading (css)
SampleWinformsAppOutput

Output from Edge Dev tools, assets loaded.
SampleWinformsAppOutputFromEdgeDevTools

Output from Edge dev tools, assets cannot be found.
SampleWinformsLibraryLoaderOutputFromEdgeDevTools

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked BlazorHybridTest repository and run both SampleWinformsApp and SampleWinformsLibrary Loader as the startup project. Compare the WebView2 asset-loading behavior and the Edge DevTools output in each configuration. Done means the DLL-hosted WinForms setup loads the Razor Class Library's static assets, including CSS, as the direct app does.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.