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

HandleUserPreferenceChanged should handle ArgumentNullException #3494

Closed
Nuklon opened this issue May 8, 2019 · 2 comments
Closed

HandleUserPreferenceChanged should handle ArgumentNullException #3494

Nuklon opened this issue May 8, 2019 · 2 comments
Labels
Milestone

Comments

@Nuklon
Copy link
Contributor

Nuklon commented May 8, 2019

Describe the bug
DetectTheme is throwing a ANE when there is no app or window. This sounds like a good idea, but there's no way to catch these exceptions as HandleUserPreferenceChanged is private. So it causes the application to crash. This doesn't happen frequently but during closing it shouldn't cause a crash as other stuff might still require a dispose or save.

Environment:

  • MahApps.Metro version: 2.0.0-alpha0309
  • OS: W10 Home

Additional context

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentNullException: Value cannot be null.
Parameter name: app
at MahApps.Metro.ThemeManager.DetectTheme(System.Windows.Application app) at offset 18 in C:\projects\mahapps-metro\src\MahApps.Metro\ThemeManager\ThemeManager.cs:line 821:col 17
at MahApps.Metro.ThemeManager.ChangeThemeBaseColor(System.Windows.Application app, System.String baseColor) at offset 0 in C:\projects\mahapps-metro\src\MahApps.Metro\ThemeManager\ThemeManager.cs:line 622:col 13
at MahApps.Metro.ThemeManager.HandleUserPreferenceChanged(System.Object sender, Microsoft.Win32.UserPreferenceChangedEventArgs e) at offset 14 in C:\projects\mahapps-metro\src\MahApps.Metro\ThemeManager\ThemeManager.cs:line 978:col 9
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(System.Object target, System.Object[] arguments, System.Signature sig, System.Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(System.Object obj, System.Object[] parameters, System.Object[] arguments) at offset 22
at System.Delegate.DynamicInvokeImpl(System.Object[] args) at offset 36
at Microsoft.Win32.SystemEvents.SystemEventInvokeInfo.InvokeCallback(System.Object arg) at offset 18
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, System.Object args, System.Int32 numArgs) at offset 142
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object source, System.Delegate callback, System.Object args, System.Int32 numArgs, System.Delegate catchHandler) at offset 2
@punker76 punker76 added the Bug label May 8, 2019
@punker76 punker76 added this to the 2.0.0 milestone May 8, 2019
punker76 added a commit that referenced this issue May 9, 2019
It could be that the current App is null when the system event UserPreferenceChanged occurs
Just check this situation now to prevent the upcoming ArgumentNullException with an additional trace warning in debug mode.
@punker76 punker76 closed this as completed May 9, 2019
@punker76
Copy link
Member

punker76 commented May 9, 2019

@Nuklon this has now been fixed, and it will be released in the next version of MahApps.Metro v2.0

@Nuklon
Copy link
Contributor Author

Nuklon commented May 9, 2019

Fantastic work, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants