dotnet / dotnet/wpf

Change from WebView2 to WebView2CompositionControl causes error in WPF app

Open
#11,917 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

### Description

A working WPF app (dotnet v.10.0.203) uses a WebView2 controller (nuget v. 1.0.4191.47) to navigate to a url. The app is executed in windows server 2022 datacenter. When changing from WebView2 to WebView2CompositionControl the app fails due to an unhandled exception:

`
Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Windows.SDK.NET, Version=10.0.17763.10, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. El sistema no puede encontrar el archivo especificado.
File name: 'Microsoft.Windows.SDK.NET, Version=10.0.17763.10, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
···
`

App must use WebView2CompositionControl but not be tied to specific sdk version (example sdk v.10.0.17763.10 provided in exception).

### Importance
Blocking. My app's basic functions are not working due to this issue.

### SDK Version
10.0.203 (dotnet --list-sdks)

### Framework
WPF

### Operating System
Windows Server 2022 datacenter

### Reproduction Steps

1. Install dotnet v. 10.0.203.
3. Generate a new WPF app: `dotnet new wpf -n WVCompositionControl`
4. Add WebView2 nuget to proyect: `dotnet add package Microsoft.Web.WebView2 -v 1.0.4191.47`
5. Add WebView2 to MainWindow.xaml:`



`

5. Execute app to verify it opens window (Will be empty).
6. Close window and modify MainWindow.xaml to use WebView2ConpositionControl: `



`
7. Execute app.

### Expected behavior

The app executed in step 5. must be identical to the app executed in step 7.

### Actual behavior

The wpf window of step 7. opens for a brief moment before closing due to unhadled exception. Using Visual Studio Code, launch ".NET Core Launch (console)". Debug console logs the following error:

`
Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Windows.SDK.NET, Version=10.0.17763.10, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. El sistema no puede encontrar el archivo especificado.
File name: 'Microsoft.Windows.SDK.NET, Version=10.0.17763.10, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
2
at Microsoft.Web.WebView2.Wpf.WebView2CompositionControl.TryInitializeD3DImage()
at Microsoft.Web.WebView2.Wpf.WebView2CompositionControl.OnApplyTemplate()
at System.Windows.FrameworkElement.ApplyTemplate()
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.Controls.Grid.MeasureOverride(Size constraint)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.Controls.Decorator.MeasureOverride(Size constraint)
at System.Windows.Documents.AdornerDecorator.MeasureOverride(Size constraint)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.Controls.Border.MeasureOverride(Size constraint)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.Window.MeasureOverrideHelper(Size constraint)
at System.Windows.Window.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.Interop.HwndSource.SetLayoutSize()
at System.Windows.Interop.HwndSource.set_RootVisualInternal(Visual value)
at System.Windows.Window.SetRootVisualAndUpdateSTC()
at System.Windows.Window.SetupInitialState(Double requestedTop, Double requestedLeft, Double requestedWidth, Double requestedHeight)
at System.Windows.Window.CreateSourceWindow(Boolean duringShow)
at System.Windows.Window.ShowHelper(Object booleanBox)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Application.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at WVCompositionControl.App.Main()`

### Regression?

Don't know. But problem fix must not be tied to specific version that could cause limitations with other packages.

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with the minimal WPF app and the MainWindow.xaml change from WebView2 to WebView2CompositionControl. Start at WebView2CompositionControl.TryInitializeD3DImage in the reported stack trace and inspect how the SDK assembly is loaded. Done means the composition control opens without FileNotFoundException across supported SDK versions.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.