Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandled File not found 0x80070002 in DwmGetColorizationParameters #593

Open
wfjsw opened this issue Apr 16, 2023 · 4 comments
Open

Unhandled File not found 0x80070002 in DwmGetColorizationParameters #593

wfjsw opened this issue Apr 16, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@wfjsw
Copy link

wfjsw commented Apr 16, 2023

Describe the bug

The DWM api is throwing a System.IO.FileNotFoundException when accessing Dwmapi.DwmGetColorizationParameters(out DWMCOLORIZATIONPARAMS dwParameters)

To Reproduce

Unknown

Expected behavior

The error is caught and a default color is applied

Screenshots

No response

OS version

Windows 10.0.22621

.NET version

.NET 6.0.16

WPF-UI NuGet version

91a7089

Additional context

System.IO.FileNotFoundException: 系统找不到指定的文件。 (0x80070002)
  ?, in void Dwmapi.DwmGetColorizationParameters(out DWMCOLORIZATIONPARAMS dwParameters)
  ?, in Color UnsafeNativeMethods.GetDwmColor()
  ?, in void Theme.Apply(ThemeType themeType, WindowBackdropType backgroundEffect, bool updateAccent, bool forceBackground)
  ?, in void Watcher.UpdateThemes(SystemThemeType systemTheme)
  ?, in void Watcher.Watch(Window window, WindowBackdropType backgroundEffect, bool updateAccents, bool forceBackground)+(object sender, RoutedEventArgs args) => { }
  ?, in void RoutedEventHandlerInfo.InvokeHandler(object target, RoutedEventArgs routedEventArgs)
  ?, in void EventRoute.InvokeHandlersImpl(object source, RoutedEventArgs args, bool reRaised)
  ?, in void UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
  ?, in void UIElement.RaiseEvent(RoutedEventArgs e)
  ?, in void BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent)
  ?, in object BroadcastEventHelper.BroadcastLoadedEvent(object root)
  ?, in void MediaContext.FireLoadedPendingCallbacks()
  ?, in void MediaContext.FireInvokeOnRenderCallbacks()
  ?, in void MediaContext.RenderMessageHandlerCore(object resizedCompositionTarget)
  ?, in object MediaContext.RenderMessageHandler(object resizedCompositionTarget)
  ?, in void MediaContext.Resize(ICompositionTarget resizedCompositionTarget)
  ?, in void HwndTarget.OnResize()
  ?, in IntPtr HwndTarget.HandleMessage(WindowMessage msg, IntPtr wparam, IntPtr lparam)
  ?, in IntPtr HwndSource.HwndTargetFilterMessage(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
  ?, in IntPtr HwndWrapper.WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
  ?, in object HwndSubclass.DispatcherCallbackOperation(object o)
  ?, in object ExceptionWrapper.InternalRealCall(Delegate callback, object args, int numArgs)
  ?, in object ExceptionWrapper.TryCatchWhen(object source, Delegate callback, object args, int numArgs, Delegate catchHandler)
@wfjsw wfjsw added the bug Something isn't working label Apr 16, 2023
@ChainsLunatic
Copy link

ChainsLunatic commented Aug 25, 2023

The exception does not occur if you pass false to Theme.Apply's updateAccent. So a possible workaround would be to try passing true and retry with passing false on FileNotFoundException, e.g.

private void ApplyTheme()
{
    try
    {
        Theme.Apply(_settings.DarkMode ? ThemeType.Dark : ThemeType.Light, WindowBackdropType, _updateAccentColor);
    }
    catch (FileNotFoundException)
    {
        if (_updateAccentColor)
        {
            _updateAccentColor = false;
            ApplyTheme();
        }
    }
}

Another way would be to determine the actual Windows version the error occurs on and implement a check for it's version number. This could probably be introduced into the actual code base also. I sadly can't do that as I got no systems to test on.

@ilyfairy
Copy link

ilyfairy commented Oct 2, 2023

There may be a problem with windows. When calling DwmGetColorizationParameters, you will encounter a 0x80070002 exception.
I tried changing the theme color in settings and the problem was solved

@YiLai-Qube
Copy link

There may be a problem with windows. When calling DwmGetColorizationParameters, you will encounter a 0x80070002 exception. I tried changing the theme color in settings and the problem was solved

Changing the colour theme and default windows mode (light/dark) in windows settings solves the problem for me

@davidegiacometti
Copy link
Contributor

I am randomly experiencing this issue while turning on/off high contrast or switching between high contrast modes
Windows 10 22H2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants