【问题标题】:Push Channel Uri shows "Cannot evaluate expression" on device. Works perfect on the emulatorPush Channel Uri 在设备上显示“无法评估表达式”。在模拟器上完美运行
【发布时间】:2012-07-14 11:59:49
【问题描述】:

我正在尝试在 Windows Phone 上实现基于推送通知的应用程序。我已经能够在模拟器上检索 Channel Uri 并通过我的服务器向模拟器发送推送通知。

另一方面,我在设备上部署相同的解决方案时遇到了问题。使用 Uri 会返回 NullReferenceException。而 Channel Uri 显示“无法评估表达式”。

这是我放置在页面构造函数中的代码。 我也尝试过更改 _pushChannelName。

private static string _pushChannelName = "TestApp";

    // Constructor
    public MainPage()
    {
        HttpNotificationChannel pushChannel;

        InitializeComponent();

        pushChannel = HttpNotificationChannel.Find(_pushChannelName);

        if (pushChannel == null) 
        {
            MessageBox.Show("NULL");
            pushChannel = new HttpNotificationChannel(_pushChannelName);

            pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(pushChannel_ChannelUriUpdated);
            pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(pushChannel_ErrorOccurred);

            pushChannel.ShellToastNotificationReceived +=new EventHandler<NotificationEventArgs>(pushChannel_ShellToastNotificationReceived);

            pushChannel.Open();

            pushChannel.BindToShellToast();
        }
        else
        {

            pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(pushChannel_ChannelUriUpdated);
            pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(pushChannel_ErrorOccurred);

            pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(pushChannel_ShellToastNotificationReceived);

            //System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString());
            textBox1.Text = pushChannel.ChannelUri.ToString();

        }

        MessageBox.Show(String.Format("Channel Uri is {0}", pushChannel.ChannelUri.ToString()));
    }

我还尝试从 ChangeUri 事件中检查 Uri。该事件不会在设备上触发,而 Push 应用程序工作正常。连频道限制都达不到。

private void pushChannel_ChannelUriUpdated(Object sender, NotificationChannelUriEventArgs e)
    {
        Dispatcher.BeginInvoke(() =>
        {

            MessageBox.Show(String.Format("Channel Uri is {0}",
                e.ChannelUri.ToString()));

        });
    }

【问题讨论】:

  • 只有在调试器绑定/下时才会发生这种情况,还是总是会发生?
  • 如果不在调试器下,应用就会崩溃。
  • 即使你只尝试在回调中读取 URI?
  • 回调根本没有触发。
  • 如果你删除了保证它崩溃的代码,回调将有机会触发。你有没有解决这个问题,并尝试查看回调是否被调用?

标签: windows-phone-7 push-notification nullreferenceexception mpns


【解决方案1】:

很多用户都遇到过这个问题。解决方案有两种。

  1. 第一个解决方案是停止所有与市场帐户相关的应用程序、游戏和其他软件,并删除或停止通知。重启手机(关机/开机)并等待 24 小时。

  2. 第二种解决方案是向 Marketplace 付款并注册您的应用程序,从 Marketplace 获取证书并插入您的应用程序。那么当打开新频道时必须使用静态类“HttpNotificationChannel”的第二个重载构造函数:

    [SecuritySafeCritical] public HttpNotificationChannel(string channelName, string serviceName);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-02
    • 1970-01-01
    • 1970-01-01
    • 2012-06-01
    • 2018-02-16
    • 2013-11-24
    • 2019-02-15
    相关资源
    最近更新 更多