Description
Description
I'm trying to share code across all my usage of WebView2 as much as possible. Of course the controls for WinUI, WPF, and WinForms are all different, because each UI framework is different. But even seemingly platform-independent types, such as CoreWebView2
have different identities. This makes it impossible to build a class library targetting CoreWebView2
and run on all platforms.
CoreWebView2
in WinUI 3 has this identity:
- Type name:
Microsoft.Web.WebView2.Core.CoreWebView2
(same) - Assembly:
Microsoft.WinUI, Version=3.0.0.0, Culture=neutral, PublicKeyToken=de31ebe4ad15742b
(different)
CoreWebView2
in WPF/WinForms has this identity:
- Type name:
Microsoft.Web.WebView2.Core.CoreWebView2
(same) - Assembly:
Microsoft.Web.WebView2.Core, Version=1.0.705.50, Culture=neutral, PublicKeyToken=2a8ab48044d2601e
(different) - NuGet package version: 1.0.705.50
Version
SDK: NuGet 1.0.705.50
Runtime: N/A
Framework: WPF/WinForms and WinUI
OS: N/A
Repro Steps
- Build a class library that uses CoreWebView2 from the WebView2 NuGet package for WPF/Winforms.
- Try to have that class library also support the WinUI CoreWebView2
Result: You can't, because the type identities are different.
Expected: The type identities of platform-independent types should be identical.
Additional context
We encountered this while working on Blazor Desktop, where we support hosting Blazor directly in WPF and WinForms, and also in WinUI (via .NET MAUI). We wanted to put most of our code in a common WebView2-aware library, and then only write thin adapters to wire it up to each UI platform. However, this is not possible because the type identities are different, so we have to duplicate all the code.