1

I have an application which uses Toast Notification library in https://github.com/rafallopatka/ToastNotifications. When I run it through visual studio it works like charm. But when I run the Exe file in my bin folder it crashes when it tries to run Toast Notification.

This is the class which contains notification params

 namespace Notifications_2019.Pages
{
    public class Notifications
    {
        public  Notifications() {


        }
        public Notifier notifier = new Notifier(cfg =>
        {

            cfg.PositionProvider = new WindowPositionProvider(

                parentWindow: Application.Current.MainWindow,
                corner: Corner.TopRight,
                offsetX: 10,
                offsetY: 10);

            cfg.LifetimeSupervisor = new TimeAndCountBasedLifetimeSupervisor(
                notificationLifetime: TimeSpan.FromSeconds(5),
                maximumNotificationCount: MaximumNotificationCount.FromCount(15));

            cfg.Dispatcher = Application.Current.Dispatcher;
        });
    }
}

This is the exception logged in windows event Viewer

Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.NullReferenceException
   at ToastNotifications.Position.WindowPositionProvider..ctor(System.Windows.Window, ToastNotifications.Position.Corner, Double, Double)
   at SACC_2019.Pages.Notifications+<>c.<.ctor>b__0_0(ToastNotifications.Core.NotifierConfiguration)
   at ToastNotifications.Notifier.CreateConfiguration()
   at ToastNotifications.Notifier.Configure()
   at ToastNotifications.Notifier.Notify[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.Func`1<System.__Canon>)
   at ToastNotifications.Messages.SuccessExtensions.ShowSuccess(ToastNotifications.Notifier, System.String)
   at SACC_2019.Classes.Page1.ParseMaterialSystemInput()
   at SACC_2019.Classes.Page1.DtaMaterial_Paste(System.Object, System.Windows.Input.ExecutedRoutedEventArgs)
   at System.Windows.Input.CommandBinding.OnExecuted(System.Object, System.Windows.Input.ExecutedRoutedEventArgs)
   at System.Windows.Input.CommandManager.ExecuteCommandBinding(System.Object, System.Windows.Input.ExecutedRoutedEventArgs, System.Windows.Input.CommandBinding)
   at System.Windows.Input.CommandManager.FindCommandBinding(System.Windows.Input.CommandBindingCollection, System.Object, System.Windows.RoutedEventArgs, System.Windows.Input.ICommand, Boolean)
   at System.Windows.Input.CommandManager.FindCommandBinding(System.Object, System.Windows.RoutedEventArgs, System.Windows.Input.ICommand, Boolean)
   at System.Windows.Input.CommandManager.OnExecuted(System.Object, System.Windows.Input.ExecutedRoutedEventArgs)
   at System.Windows.UIElement.OnExecutedThunk(System.Object, System.Windows.Input.ExecutedRoutedEventArgs)
   at System.Windows.Input.ExecutedRoutedEventArgs.InvokeEventHandler(System.Delegate, System.Object)
   at System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate, System.Object)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(System.Object, System.Windows.RoutedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(System.Object, System.Windows.RoutedEventArgs, Boolean)
   at System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject, System.Windows.RoutedEventArgs)
   at System.Windows.UIElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs)
   at System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs, Boolean)
   at System.Windows.Input.RoutedCommand.ExecuteImpl(System.Object, System.Windows.IInputElement, Boolean)
   at System.Windows.Input.RoutedCommand.ExecuteCore(System.Object, System.Windows.IInputElement, Boolean)
   at System.Windows.Input.CommandManager.TranslateInput(System.Windows.IInputElement, System.Windows.Input.InputEventArgs)
   at System.Windows.UIElement.OnKeyDownThunk(System.Object, System.Windows.Input.KeyEventArgs)
   at System.Windows.Input.KeyEventArgs.InvokeEventHandler(System.Delegate, System.Object)
   at System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate, System.Object)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(System.Object, System.Windows.RoutedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(System.Object, System.Windows.RoutedEventArgs, Boolean)
   at System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject, System.Windows.RoutedEventArgs)
   at System.Windows.UIElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs)
   at System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs, Boolean)
   at System.Windows.Input.InputManager.ProcessStagingArea()
   at System.Windows.Input.InputManager.ProcessInput(System.Windows.Input.InputEventArgs)
   at System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input.InputReport)
   at System.Windows.Interop.HwndKeyboardInputProvider.ReportInput(IntPtr, System.Windows.Input.InputMode, Int32, System.Windows.Input.RawKeyboardActions, Int32, Boolean, Boolean, Int32)
   at System.Windows.Interop.HwndKeyboardInputProvider.ProcessKeyAction(System.Windows.Interop.MSG ByRef, Boolean ByRef)
   at System.Windows.Interop.HwndSource.CriticalTranslateAccelerator(System.Windows.Interop.MSG ByRef, System.Windows.Input.ModifierKeys)
   at System.Windows.Interop.HwndSource.OnPreprocessMessage(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
   at System.Windows.Threading.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority, System.Delegate, System.Object)
   at System.Windows.Interop.HwndSource.OnPreprocessMessageThunk(System.Windows.Interop.MSG ByRef, Boolean ByRef)
   at System.Windows.Interop.HwndSource+WeakEventPreprocessMessage.OnPreprocessMessage(System.Windows.Interop.MSG ByRef, Boolean ByRef)
   at System.Windows.Interop.ComponentDispatcherThread.RaiseThreadMessage(System.Windows.Interop.MSG ByRef)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)
   at System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame)
   at System.Windows.Application.RunDispatcher(System.Object)
   at System.Windows.Application.RunInternal(System.Windows.Window)
   at System.Windows.Application.Run(System.Windows.Window)
   at System.Windows.Application.Run()
VillageTech
  • 1,968
  • 8
  • 18
Tharaka
  • 47
  • 6
  • 6
    "but still it does not work." .. what do you mean by that? Please provide minimal reproducible code. – Jawad Dec 26 '19 at 17:04
  • 3
    Please include as an edit to your question the execption that should be getting logged in the windows event viewer when run as a standalone exe with its full message and stack trace – Scott Chamberlain Dec 26 '19 at 17:05
  • Since you copied the files and subdirectories in the bin folder and it doesn’t work, does it work if you double-click on the exe in the bin directory? – jwezorek Dec 26 '19 at 17:13
  • 5
    The error shows that inside of the constructor `new WindowPositionProvider( parentWindow: Application.Current.MainWindow, corner: Corner.TopRight, offsetX: 10, offsetY: 10);` is thowing a NullReferenceException. So either MainWindow is null or Corner.TopRight is (and i dont think top right can be null). See [What is a NullReferenceException, and how do I fix it](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) for details on how to debug the issue. – Scott Chamberlain Dec 26 '19 at 17:33
  • This is no longer off-topic as debugging help, but it's a duplicate, so voting to leave closed. – pppery Dec 26 '19 at 18:20
  • 1
    Possible duplicate of [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – pppery Dec 26 '19 at 21:50

0 Answers0