Closed
Description
Copied from ADO ID 893177
- Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes
We have a bug here - a missing check.
\WPF\src\Core\CSharp\MS\Internal\DpiUtil\DpiUtil+DpiAwarenessScope.cs
[SecuritySafeCritical]
private DpiAwarenessScope(
DpiAwarenessContextValue dpiAwarenessContextValue,
bool updateIfThreadInMixedHostingMode,
bool updateIfWindowIsSystemAwareOrUnaware,
IntPtr hWnd)
{
if (!OperationSupported)
{
return;
}
if (updateIfThreadInMixedHostingMode && !this.IsThreadInMixedHostingBehavior)
{
return;
}
if (updateIfWindowIsSystemAwareOrUnaware &&
(hWnd == IntPtr.Zero || !this.IsWindowUnawareOrSystemAware(hWnd)))
{
return;
}
try
{
this.OldDpiAwarenessContext =
UnsafeNativeMethods.SetThreadDpiAwarenessContext(
new DpiAwarenessContextHandle(dpiAwarenessContextValue));
}
catch (Exception e) when (e is EntryPointNotFoundException || e is MissingMethodException || e is DllNotFoundException)
{
OperationSupported = false;
}
}
We should either be catch KeyNotFoundException
, or better yet, checking for dpiAwarenessContextValue==Invalid
and return with OperationSupported=false
early in the constructor.
Found from Watson data:
Call Stack
- mscorlib.ni!System.Collections.Generic.Dictionary_2[[MS.Utility.DpiAwarenessContextValue,_WindowsBase],[System.IntPtr,_mscorlib]].get_Item
- at PresentationCore.ni!MS.Internal.DpiUtil in DpiUtil+DpiAwarenessScope.cs
- at PresentationFramework.ni!System.Windows.SystemResources.CreateResourceChangeListenerWindow in SystemResources.cs
- at PresentationFramework.ni!System.Windows.SystemResources.EnsureResourceChangeListener in SystemResources.cs
- at PresentationFramework.ni!System.Windows.SystemResources.GetDpiAwarenessCompatibleNotificationWindow in SystemResources.cs
- at PresentationFramework.ni!System.Windows.Interop.HwndHost.BuildOrReparentWindow in HwndHost.cs
- at PresentationFramework.ni!System.Windows.Interop.HwndHost.OnSourceChanged in HwndHost.cs
- at PresentationCore.ni!System.Windows.SourceChangedEventArgs.InvokeEventHandler in SourceChangedEventArgs.cs
- at PresentationCore.ni!System.Windows.RoutedEventArgs.InvokeHandler in RoutedEventArgs.cs
- at PresentationCore.ni!System.Windows.RoutedEventHandlerInfo.InvokeHandler in RoutedEventHandlerInfo.cs
- at PresentationCore.ni!System.Windows.EventRoute.InvokeHandlersImpl in EventRoute.cs
- at PresentationCore.ni!System.Windows.UIElement.RaiseEventImpl in UIElement.cs
- at PresentationCore.ni!System.Windows.UIElement.RaiseEvent in UIElement.cs
- at PresentationCore.ni!System.Windows.PresentationSource.UpdateSourceOfElement in PresentationSource.cs
- at PresentationCore.ni!System.Windows.PresentationSource.RootChanged in PresentationSource.cs
- at PresentationCore.ni!System.Windows.Interop.HwndSource.set_RootVisualInternal in HwndSource.cs
- at PresentationCore.ni!System.Windows.Interop.HwndSource.Dispose in HwndSource.cs
- at PresentationCore.ni!System.Windows.Interop.HwndSource.OnHwndDisposed in HwndSource.cs
- at WindowsBase.ni!MS.Win32.HwndWrapper.Dispose in HwndWrapper.cs
- at WindowsBase.ni!MS.Win32.HwndWrapper.WndProc in HwndWrapper.cs
- at WindowsBase.ni!MS.Win32.HwndSubclass.DispatcherCallbackOperation in HwndSubclass.cs
- at WindowsBase.ni!System.Windows.Threading.ExceptionWrapper.InternalRealCall in ExceptionWrapper.cs
- at WindowsBase.ni!System.Windows.Threading.ExceptionWrapper.TryCatchWhen in ExceptionWrapper.cs
- at WindowsBase.ni!System.Windows.Threading.Dispatcher.LegacyInvokeImpl in Dispatcher.cs
- at WindowsBase.ni!MS.Win32.HwndSubclass.SubclassWndProc in HwndSubclass.cs