2011-02-04 2 views
2

Вот мой код. Все работает отлично при первом запуске, т. Е. HttpNotificationChannel.Find() возвращает значение null.Почему HttpNotificationChannel.Open бросает ArgumentException() E_INVALIDARG?

Но во второй раз, когда я запускаю его, Find() возвращает правильную вещь, однако, когда я получаю вызов Open(), он выдает исключение. Что действительно странно, так как Open() не принимает никаких аргументов.

Что я делаю неправильно?

public string ChannelName = "MyAppChannel"; 
    ... 
    NotificationChannel = HttpNotificationChannel.Find(ChannelName); 
    if (NotificationChannel == null) 
    { 
    NotificationChannel = new HttpNotificationChannel(ChannelName); 
    } 
    NotificationChannel.ChannelUriUpdated += new EventHandler(Channel_ChannelUriUpdated); 
    NotificationChannel.HttpNotificationReceived += new EventHandler(NotificationChannel_HttpNotificationReceived); 
    NotificationChannel.ErrorOccurred += new EventHandler(Channel_ErrorOccurred); 
    NotificationChannel.Open();   // <-- Kaboom here, the 2nd time 

Вот полный текст и стек:

System.ArgumentException: E_INVALIDARG 
    at Microsoft.Phone.Notification.SafeNativeMethods.ThrowExceptionFromHResult(Int32 hr, Exception defaultException, NotificationType type) 
    at Microsoft.Phone.Notification.HttpNotificationChannel.Open() 
    at LiveShare.NotificationManager.Initialize() 
    at LiveShare.App..ctor() 
    at System.Reflection.RuntimeConstructorInfo.InternalInvoke(RuntimeConstructorInfo rtci, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark) 
    at System.Reflection.RuntimeConstructorInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark) 
    at System.Reflection.ConstructorInfo.Invoke(Object[] parameters) 
    at MS.Internal.TypeProxy.<>c__DisplayClass30.b__2a() 
    at MS.Internal.TypeProxy.CreateInstance(UInt32 customTypeId) 
    at MS.Internal.FrameworkCallbacks.CreateKnownObject(IntPtr nativeRootPeer, UInt32 customTypeId, String initializationString, IntPtr& nativePeer, UInt32 isCreatedByParser) 
    at MS.Internal.FrameworkCallbacks.CreateUnknownObject(String assemblyName, String typeName, IntPtr nativeRootPeer, String initializationString, UInt32& customTypeId, UInt32& coreTypeId, UInt32& typeFlags, IntPtr& nativePeer) 

ответ

2

Правильное решение не должно называть Open(), если Find() преуспевает.

1

Это выглядит очень похоже на документированной проблемы с CTP как described by Nick Harris в апреле прошлого года.

Решение: При попытке открыть канал почти сразу же после того, как вы нажмете Debug, когда произойдут эмулятор пожары этого вопроса. Решение прост - дайте эмулятор за две минуты до совершения вызова.

В случае, если это не так, есть хорошая статья о Silverlight Show, которая охватывает push-уведомления в приложении котировки акций WP7.

+0

Это случается, когда я развертываю телефон также ... –

+0

Нет, это совсем другое. Я подозреваю, что я просто не должен называть Open(), если Find() преуспевает ... –

Смежные вопросы