[Windows Phone 7 Software Development] otherworld:
Hi,

The error report you generate is at the bottom of this message. As you can probably see (if I'm reading it correctly) the error (for my device at least) is not actually the loading of the categories - it seems to be the when you open the push channel as you have no try catch around that.

Note the interesting .net behaviour (if I'm reading your code correctly) that when you first check the error in LoadCompletedEventArgs 'e' of categories_LoadCompleted it is null, but when you subsequently check it - after the open push channel attempt - it contains the push channel exception. It must just retrieve the latest async open error (i.e. that of the push channel not opening).

I would suggest you wrap your push channel open code with a try catch that does the following:

catch (InvalidOperationException e)

{

HandleInvalidOperationException(e);

return;

}

catch (Exception e)

{

// if you're here it's most likely an error in your code rather than one with the push channel

}

This is the sort of things I check for and handle appropriately (if you find a way of checking a code or enum rather than a string match on the message text let me know):

private void HandleInvalidOperationException(InvalidOperationException e)

{

if (e.Message == "Channel not opened")

{

//This exception is raised when a notification channel has not been opened yet for raw notifications.

}

else if (e.Message == "Failed to open channel")

{

//This exception is raised when the notification channel failed to open. Try opening the notification channel again.

}

else if (e.Message == "Channel quota exceeded")

{

//This exception is raised when either trying to open more than one notification channel per application, or when trying to open more than 15 notification channels per device.

}

//InvalidOperationException(Notification server temporarily unavailable)

else if (e.Message == "Notification server temporarily unavailable")

{

//The Microsoft Push Notification Service is unavailable.

}

// unknown if you reach here

}

I also check if there is a channel uri after opening (there sometimes isn't) and if there isn't I set a timer to check it every second until 60 seconds have passed. If it reaches 60 and the uri updated event hasn't fired I assume that the device's power level is too low for a push channel at the moment (about 25% battery will do this on some devices).

It sounds like you could just continue past your current issue though -i.e. your problem may well be the Push call, not the load categories, so with the right try catch etc. (with a revised/recoded check on whether the categories have loaded) you could always continue into the app with a gentle warning that push might be down. Have a play with that second error check in the load categories completed event - you might instead want to have that second 'if' as an 'else if' so that it doesn't get confused by subsequent errors (i.e. other than the categories loading service call).

Hope that's helped.

Cheers,

Ian

Your error report:

Query URL: /JokeCategories?$filter=Hidden eq 0

Outer Exception Message:

Failed to open channel

Outer Exception StackTrace:

at Microsoft.Phone.Notification.SafeNativeMethods.ThrowExceptionFromHResult(Int32 hr, Exception defaultException, NotificationType type)

at Microsoft.Phone.Notification.HttpNotificationChannel.Open()

at FunnyJokes.MainPage.SubscribeToPush()

at FunnyJokes.MainPage.categories_LoadCompleted(Object sender, LoadCompletedEventArgs e)

at System.Data.Services.Client.DataServiceCollection`1.<>c__DisplayClassd.<>c__DisplayClassf.<BeginLoadAsyncOperation>b__b()

at System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)

at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)

at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)

at System.Delegate.DynamicInvokeOne(Object[] args)

at System.MulticastDelegate.DynamicInvokeImpl(Object[] args)

at System.Windows.Threading.DispatcherOperation.Invoke()

at System.Windows.Threading.Dispatcher.Dispatch(DispatcherPriority priority)

at System.Windows.Threading.Dispatcher.OnInvoke(Object context)

at System.Windows.Hosting.CallbackCookie.Invoke(Object[] args)

at System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(IntPtr pHandle, Int32 nParamCount, ScriptParam[] pParams, ScriptParam& pResult)