[Problem/Bug]: [WPF] WebView2CompositionControl: ArgumentException (E_INVALIDARG) in GraphicsItemD3DImage.RecoverAfterDisplayChange is not retried and leaves the control blank
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 8/100
- Tipo di issue
- Bug
- Chiarezza
- Da chiarire
- Stato di attività
- Attiva
- Stack tecnologico
- csharp
- Ambito
- desktop-dev
Direzione di ricerca
The report concerns the closed-source WebView2 WPF SDK, and the repository holds only feedback, so no source is available here. The payload names GraphicsItemD3DImage.RecoverAfterDisplayChange, Direct3DHelper.CreateD3D9Device and the catch blocks that handle only COMException. Done would mean a reproducible trigger or a maintainer-confirmed fix, and the work is for maintainers rather than a first contribution.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
What happened?
After a display settings change, GraphicsItemD3DImage.RecoverAfterDisplayChange threw an unhandled System.ArgumentException ("Value does not fall within the expected range", HRESULT 0x80070057) from Direct3DHelper.CreateD3D9Device. The built-in retry logic only catches COMException, so no retry was scheduled, the exception reached the WPF Dispatcher, and the control is left in a state where it no longer renders. With a debugger attached the process terminated; without one the app would survive, but (from my reading of the IL below, I have not seen the blank page on screen) the WebView area would stay blank for the rest of the process lifetime.
The app (WPF + BlazorWebView, which uses WebView2CompositionControl) was left running unattended, started from Visual Studio, and the screen was most likely asleep. The exception was raised from a Dispatcher operation posted by OnDisplaySettingsChanged (a SystemEvents.DisplaySettingsChanged notification). I could not confirm the trigger.
Stack trace
System.ArgumentException: Value does not fall within the expected range.
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
at Microsoft.Web.WebView2.Wpf.Direct3DHelper.CreateD3D9Device(IntPtr mainwindow)
at Microsoft.Web.WebView2.Wpf.GraphicsItemD3DImage.RecoverAfterDisplayChange()
at Microsoft.Web.WebView2.Wpf.GraphicsItemD3DImage.<OnDisplaySettingsChanged>b__48_0()
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 System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
...
at System.Windows.Application.RunInternal(Window window)
Related issues
Searching this repository for RecoverAfterDisplayChange and CreateD3D9Device returns no results. These issues are in the same area (display changes with WebView2CompositionControl) but report different failures:
- #5437 (closed):
UCEERR_RENDERTHREADFAILUREon monitor unplug; a comment says it was believed fixed in SDK 1.0.4191.47 ("Fixed a WPF crash from changing the display topology in composition-controlled apps"). - #5774 (open, tracked):
UCEERR_RENDERTHREADFAILURE/ hang on monitor disconnect, still reproducing with 1.0.4314.35; it also mentions aNullReferenceExceptioninDirect3DHelper.GetSharedHandlecalled fromGraphicsItemD3DImage.RequestRender. - #5653, #5636, #5575: other
GraphicsItemD3DImage/WebView2CompositionControlfailures.
The failure reported here is a different one: a managed ArgumentException from the display-change recovery path itself, which the retry logic does not catch.
Analysis (from the shipped IL; no source available)
OnDisplaySettingsChangingsets_displayChangePending = trueand clears the D3DImage back buffer.OnDisplaySettingsChangedposts a lambda (<OnDisplaySettingsChanged>b__48_0) that callsRecoverAfterDisplayChange()insidetry { } catch (COMException) { start a 500 ms DispatcherTimer }. The timer tick (<>c__DisplayClass48_0.<OnDisplaySettingsChanged>b__1) retries up to 20 times and also catches onlyCOMExceptionandObjectDisposedException.RecoverAfterDisplayChangeclears the back buffer, releases the devices, creates the D3D11 device (succeeds), then callsDirect3DHelper.CreateD3D9Device(hwnd), which runsDirect3DCreate9ExandIDirect3D9Ex.CreateDevice(adapter 0, HAL, windowed) and passes each result throughMarshal.ThrowExceptionForHR. It fails there; from the stack alone I cannot tell which of the two calls returned E_INVALIDARG.Marshal.ThrowExceptionForHR(0x80070057)throwsArgumentException, notCOMException(checked on .NET 10:0x8876086CD3DERR_INVALIDCALL and0x887A0005DXGI_ERROR_DEVICE_REMOVED do throwCOMException;0x8007000EthrowsOutOfMemoryException). So for E_INVALIDARG neither the first call nor any tick is protected, and the retry timer is never started._displayChangePendingis cleared in only three places: the end of a successfulRecoverAfterDisplayChange, its_hwndSource == nullearly return, and the 20th timer tick. After the failure above none of them runs, so the flag staystrue. While it istrue,RequestRenderreturns immediately (disposing the captured frame), so nothing is drawn any more, and the back buffer was set to null byClearBackBuffer.- Separately: if the retry timer does run and all 20 attempts fail with
COMException, the tick silently clears_displayChangePendingand stops the timer, leaving the control with released/missing devices and no notification to the host app.
Suggested fix
- In both the initial call and the timer tick, catch
ArgumentException(or simplyException) in addition toCOMException, so the retry is scheduled. - Do not leave
_displayChangePendingset forever, and do not silently clear it when retries are exhausted: surface a failure the host can handle (an event, or aProcessFailed-style notification). - Consider re-running the recovery when
IsFrontBufferAvailableChangedfires or on the next display/session notification, not only from the singleDisplaySettingsChangedevent. - Make
RecoverAfterDisplayChangesafe to call repeatedly after a partial failure.
Workaround in use
Handle Application.DispatcherUnhandledException: if any stack frame belongs to Microsoft.Web.WebView2.Wpf.GraphicsItemD3DImage or Direct3DHelper, mark the exception handled and call the private GraphicsItemD3DImage.RecoverAfterDisplayChange through reflection from a DispatcherTimer (500 ms, then every 5 s) until it stops throwing. This was only tested with a simulated exception; I have not confirmed that it revives a real dead surface.
Not known
- The real trigger (display sleep, topology change, session lock, RDP) and a deterministic way to reproduce it.
- Which of the two
ThrowExceptionForHRcalls inCreateD3D9Devicereturned E_INVALIDARG. - Whether a successful retry fully restores rendering after this failure.
- Whether SDK 1.0.4314.35 behaves differently; I have only observed this on 1.0.4258.31.
Importance
Important. My app's user experience is significantly compromised.
Runtime Channel
Stable release (WebView2 Runtime)
Runtime Version
156.0.4314.58 (currently installed; the runtime may have auto-updated since the crash)
SDK Version
1.0.4258.31
Framework
WPF
Operating System
Windows 11
OS Version
Windows 11 Pro 26H2, build 26300.9818
Repro steps
I do not have a deterministic repro. It happened once while the app was left running unattended (started from Visual Studio), and the screen was most likely asleep. I could not confirm which display event triggered it.
Setup: a WPF app showing a WebView2CompositionControl (in my case through BlazorWebView), SDK 1.0.4258.31.
- While the control is shown, a display settings change happens (suspected: display sleep or a display being removed; not confirmed).
SystemEvents.DisplaySettingsChangedfires andGraphicsItemD3DImagepostsRecoverAfterDisplayChangeto the Dispatcher.Direct3DHelper.CreateD3D9Devicefails withE_INVALIDARG(0x80070057), whichMarshal.ThrowExceptionForHRturns intoArgumentException.
Expected: the recovery is retried until it succeeds (or a failure is reported to the host app), whatever exception type the HRESULT maps to.
Actual: the ArgumentException is not caught, no retry timer is started, it reaches Application.DispatcherUnhandledException (and terminates the process when a debugger is attached), and _displayChangePending stays true, so RequestRender drops every frame afterwards.
Repros in Edge Browser
No, issue does not reproduce in the corresponding Edge version
Regression
Don't know
Last working version (if regression)
No response
- Lingua principale
- PowerShell
- Stelle
- 526
- Fork
- 70
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di MicrosoftEdge/WebView2Feedback
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 72/100
MicrosoftEdge/WebView2Feedback#5749 · 1 commento ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
MicrosoftEdge/WebView2Feedback#5798 ·
-
[Problem/Bug]: Runtime 157 suppresses <input type="file"> in Outlook add-in task panes ("top-level window size is smaller than the minimum required size (400x300)")Forse già presa @ambikakunnath l’ha presa 1 giorno fa. Apertaregression
MicrosoftEdge/WebView2Feedback#5797 · 1 assegnatario ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
MicrosoftEdge/WebView2Feedback#5796 ·
-
[Problem/Bug]: PDF viewer fails on inline page dictionaries in /Kids; standalone WPF reproductionApertabug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
MicrosoftEdge/WebView2Feedback#5795 · 2 commenti ·
Tutte le issue di MicrosoftEdge/WebView2Feedback
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
NousResearch/hermes-agent#151154 ·
I maintainer di solito rispondono entro 1 giorno
-
Bug: on hover a tab's name in Cra stops ~16 pt short of Arc's, with 24 pt of air before the ✕Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
VictorKildahl/cra#243 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
bggRGjQaUbCoE/PiliPlus#3522 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
desktop v3 windows
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
esengine/DeepSeek-Reasonix#15016 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno