mjrousos / BeanTrader

Sample WPF app for demonstrating .NET Core 3 migration
5 stars 5 forks source link

Argument Null Exception on startup #1

Closed rido-min closed 5 years ago

rido-min commented 5 years ago

I cloned the repo, F5 and got the next exception

System.ArgumentNullException
  HResult=0x80004003
  Message=Value cannot be null.
Parameter name: accentName
  Source=MahApps.Metro
  StackTrace:
   at MahApps.Metro.ThemeManager.GetAccent(String accentName)
   at BeanTraderClient.App.OnStartup(StartupEventArgs e) in C:\code\BeanTrader\BeanTraderClient\App.xaml.cs:line 32
   at System.Windows.Application.<.ctor>b__1_0(Object unused)
   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.DispatcherOperation.InvokeInSecurityContext(Object state)
   at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(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 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.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at System.Windows.Application.Run(Window window)
   at System.Windows.Application.Run()
   at BeanTraderClient.App.Main()
mjrousos commented 5 years ago

Thanks for catching this, @rido-min. Seems that we're not getting the theme color name from App.config for some reason. The line that's null-ref'ing is:

ThemeManager.ChangeAppStyle(Application.Current,
  ThemeManager.GetAccent(ConfigurationManager.AppSettings["DefaultTheme"]),
  currentTheme);

And the parameter that is null seems to be ConfigurationManager.AppSettings["DefaultTheme"].

Probably this is a case of me not checking something in or something like that (since it works on my machine). I'll double-check that the config file is added, as needed, etc. and report back.

mjrousos commented 5 years ago

Simple mistake on my part- I wasn't including the app config file in build output. Probably I didn't notice the issue locally because I had BeanTrader.exe.config already in my bin folder and wasn't cleaning output.

Should be fixed now.