TypeInitializationException, ToastPromt, WP7

Mar 12, 2013 at 9:22 AM
Edited Mar 12, 2013 at 9:23 AM
Hi! I get a error when I try to initialized ToastPromt
I do this:
ToastPromt toast = new ToastPromt(); // here I get error
error Message:
[TypeInitialization_Type]
Arguments: Coding4Fun.Toolkit.Controls.PopUp`2
Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See http://go.microsoft.com/fwlink/?linkid=106663&Version=4.0.50829.0&File=mscorlib.dll&Key=TypeInitialization_Type
staktrace:
at Coding4Fun.Toolkit.Controls.PopUp`2..ctor()
at PushNotification.ToastPrompt..ctor()
at PushNotification.MainPage._myChannel_ShellToastNotificationReceived(Object sender, NotificationEventArgs e)
How can I fix it?
Thanks!
Coordinator
Mar 12, 2013 at 9:50 PM
Can you provide more about what you're doing? Target platform, where the code is, can you give me a repo so I can see exactly what is going on?
  • clint
Mar 13, 2013 at 9:01 AM
Edited Mar 13, 2013 at 9:03 AM
I do this:
var _myChannel = new HttpNotificationChannel(notifiationChannelName);
_myChannel.ShellToastNotificationReceived += _myChannel_ShellToastNotificationReceived;

private void _myChannel_ShellToastNotificationReceived(object sender, NotificationEventArgs 
{
            StringBuilder sb = new StringBuilder();

            foreach (string key in e.Collection.Keys)
            {
                sb.AppendFormat("{0}\n", e.Collection[key]);
            }

            var res = sb.ToString().Split(Convert.ToChar("\n"));
            
           try
           {
           ToastPrompt toast = new ToastPrompt(); // here I get an error
           toast.Title = res[0];
            toast.Message = res[1];
           toast.ImageSource =new BitmapImage(new Uri( "ApplicationIcon.png", UriKind.RelativeOrAbsolute));
              toast.Show();
               }
              catch (Exception exception)
               {
                   Debug.WriteLine(exception);
               }
}
In this way, I do not get the error, but and ToastPrompt not displayed
 private void _myChannel_ShellToastNotificationReceived(object sender, NotificationEventArgs 
{
            StringBuilder sb = new StringBuilder();

            foreach (string key in e.Collection.Keys)
            {
                sb.AppendFormat("{0}\n", e.Collection[key]);
            }

            var res = sb.ToString().Split(Convert.ToChar("\n"));
            try
            {
                Dispatcher.BeginInvoke(() =>
                                           {
                                               try
                                               {
                                                   ToastPrompt toast = new ToastPrompt();

                                                   toast.Title = res[0];
                                                   toast.Message = res[1];
                                                   toast.ImageSource =
                                                       new BitmapImage(new Uri(
                                                                           "ApplicationIcon.png",
                                                                           UriKind
                                                                               .RelativeOrAbsolute));
                                                   toast.Show();
                                               }
                                               catch (Exception exception)
                                               {
                                                   Debug.WriteLine(exception);
                                               }
                                           });
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception);
            }
}
Targt platform: WP7.1
Coordinator
Mar 13, 2013 at 10:04 PM
think I know what is happening already BUT this is throwing an exception when you're in the application already or are you in like the homescreen?
Mar 14, 2013 at 5:07 PM
This method( ShellToastNotificationReceived) is called when the application running and push notification comes.
Coordinator
Mar 16, 2013 at 8:31 PM
ok, i'm going to have to create a push notification framework tester for this then to verify. I'm going to upgrade this into a bug.
Coordinator
Mar 16, 2013 at 8:32 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Mar 17, 2013 at 8:16 PM
So I verified you do need a dispatcher at a more primitive level with Notification Received when touching any control. I'm taking you can't even declare a Button without it throwing an exception. So that part of the bug is "Cannot Fix".

Why your toast prompt isn't being displayed I don't know since the repo I created, it displays 100% of the time. My repo is checked in under the "Bugs" directory. I need a repo created by you else I can't figure out what is going on.

Long story short, I need more from you before I can track down why it isn't displaying.

Are you 100% sure the notification was sent out?
  • clint
Mar 17, 2013 at 8:35 PM
Hi! Here my repo where I get a error. You can try to receiving notifications when phone app is running and 100% you too get a error.

The notification 100% sent succesfully, because I recive then manually by ASP project and they successfully processed by phone system. I get the error only when I'm using ToastPromt =(
Coordinator
Mar 17, 2013 at 8:37 PM
FYI: If you create a ticket on Codeplex, you can upload a zip there. discussions you can't attach a file :-)
Mar 17, 2013 at 8:41 PM
ok, tell me how can I do it! =)
Coordinator
Mar 17, 2013 at 8:47 PM
issue tracker tab ->new issue

http://coding4fun.codeplex.com/WorkItem/Create is the direct URL
Mar 17, 2013 at 9:28 PM
I attached the repo here
Mar 18, 2013 at 10:24 AM
can you show me your test repo where you 100% get the notification whith ToastPromt when application is running. Maybe I'm doing something wrong and initialized ToastPromt not as it should...
Coordinator
Mar 18, 2013 at 3:42 PM
moving discussion for this onto the bug.
Mar 18, 2013 at 4:00 PM
Edited Mar 18, 2013 at 4:05 PM
the problem was resolved by static method where I initiated ToastPromt. Thx for your help

I did it:
public class InApp
    {
        public static void Show(string title, string message)
        {
            if (string.IsNullOrEmpty(message))
                return;

            ToastPrompt toastPrompt = new Coding4Fun.Toolkit.Controls.ToastPrompt();
            toastPrompt.Title = title;
            toastPrompt.Message = message;
            toastPrompt.TextWrapping = TextWrapping.NoWrap;
            toastPrompt.ImageSource = new BitmapImage(new Uri("ApplicationIcon.png", UriKind.RelativeOrAbsolute));
           
            toastPrompt.Show();
        }
}
and
private void MyChannelToastShellToastNotificationReceived(object sender, NotificationEventArgs e)
        {
            StringBuilder sb = new StringBuilder();

            foreach (string key in e.Collection.Keys)
            {
                sb.AppendFormat("{0}\\", e.Collection[key]);
            }

            var res = sb.ToString().Split(Convert.ToChar("\\"));
            try
            {
                Dispatcher.BeginInvoke(() =>
                    InApp.Show(res[0],res[1]));
                

            }
            catch (Exception exc)
            {
                Debug.WriteLine(exc);
            }
        }
all works fine =)
Aug 28, 2013 at 5:41 AM
Try this
private void BreadToast()
        {
            var toast = new ToastPrompt
            {
                Title = "Hello!",
                Message = "Hello bread toast! :D"
            };
            toast.Show();
        }
then call this anywhere through a Dispatcher
Dispatcher.BeginInvoke(() => BreadToast());
Coordinator
Aug 28, 2013 at 4:38 PM
this executes fine under the current release of 2.0.7 on at least being called from a button click.

There has to be more to what you're doing here. Please create a ticket and include repro project (https://coding4fun.codeplex.com/WorkItem/Create).

ikibiki wrote:
Try this
private void BreadToast()
        {
            var toast = new ToastPrompt
            {
                Title = "Hello!",
                Message = "Hello bread toast! :D"
            };
            toast.Show();
        }
then call this anywhere through a Dispatcher
Dispatcher.BeginInvoke(() => BreadToast());