0

I have a background agent on my app that works well until I send a toast notification, it throws an unhandled exception with the exception object message being: "Object reference not set to an instance of an object." The OnInvoke method is async as I do async request that works perfectly. The piece of code that throws the exception is the following

            ShellToast toast = new ShellToast();
            toast.Title = "hello";
            toast.Show();

I have no clue on where the issue might be, thanks in advance for the help.

Edit: Here is the Stacktrace:

at Microsoft.Phone.Shell.ShellToast.Show()
at ScheduledTaskAgent1.ScheduledAgent.<OnInvoke>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.   <ThrowAsync>b__4(Object state)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
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.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

1 Answers1

0

You can use another simple toast, just go to NuGet Packages, search for Toastinet and install it or download it from here.

After download add its namespace to .xaml file as below

xmlns:toastinet="clr-namespace:Toastinet;assembly=Toastinet"

and declaretion of toast is as below

<toastinet:Toastinet Grid.ColumnSpan="2" x:Name="myToast"
                          Duration="1"
                         Height="50"
                         FontSize="20"
                          Margin="0,10,0,0"
                          ShowLogo="False"
                         AnimationType="Vertical"
                         Background="#FFFFFF "
                         Foreground="#4e0916"
                         TextWrapping="Wrap"
                         Canvas.ZIndex="1"
                         VerticalAlignment="Top" />

And use this toast anywhere in .cs. as below

this.myToast.Message="hello";
Charan Ghate
  • 1,384
  • 15
  • 32