So i seem to have stumbled across a bug in the Windows Phone 7 Live Tile update toast notification update API. The bug occurs while sending a tile update URL using toast notifications that are longer in length than 260 characters. While you may think this is a problem that only affects extreme/edge usage cases, in situations where you need to pull a tile from an SSL path that contains security keys or other query string parameter data and this data is longer than this 260 character limit, you come to a dead end.
NOTE: Before i continue, i must add that I sent the attached sample project to Brandon Watson from the Windows Phone 7 development team about 2 months ago, and am awaiting an update on the issue – hopefully I'll hear back on this soon. I consider the time i have waited before sharing this information as more than enough to either report the issue to developers or myself or in the most awesome extreme case, fix the issue (the latter is a lot less likely given some people are still waiting for their Windows Phone 7 No-do update).
Toast XML Tile Updates
When using an HttpNotificationChannel to receive Toast Live Tile updates, issues arise when you attempt to receive a toast live tile update that contains a tile URL that is longer than the aforementioned 260 characters.
When receiving this tile URL an extremely generic error is thrown:
“Message contains bad contents”
This is quite annoying as the details of the above error are totally unrelated to its cause, as it relates to an internet URL request being sent without binding a shell tile update to this URL first – this is definitely not the case in my examples, or my in-detail research while attempting to find a solution to this problem. When i first came across this issue, i was totally stumped.
I scratched my head on it for a few days, asked around on StackOverflow and the MSDN forums before i even thought the long URL could have been the cause. After playing with the length of the URL for a while it appeared pretty apparent, but i wanted to know more.
Example Tile Update XML
The following is an example of a Live Tile Toast notification update received in XML over an HttpNotificationChannel:
<?xml version="1.0" encoding="utf-8"?> <wp:Notification xmlns:wp="WPNotification"> <wp:Tile> <wp:BackgroundImage> http://www.mysite.com/test.jpg</wp:BackgroundImage> <wp:Count>12</wp:Count> <wp:Title>New App Title</wp:Title> </wp:Tile> </wp:Notification>
As you can see it’s simply a bunch of parameters to let the Windows Phone 7 OS know where to get the tile from, the new Title for the Tile and an integer to overlay in case you want to display a number of updates at a time.
Tile XML that causes the error
The following XML tile update shows a tile URL update value that produces the error mentioned.
<?xml version="1.0" encoding="utf-8"?> <wp:Notification xmlns:wp="WPNotification"> <wp:Tile> <wp:BackgroundImage> https://www.mysite.com/test.jpg?param=DQAAALUAAACfeLT0FMGeakTyE9li2woy2hRITBEd05_jsHnQsL8DqY-7aCuH77GR3QjKBJ5ESpSeKTEXYnkMpspEthw0SoeJznpQT01abclcEN361o0Z754uiiP_aIrOVmFrdgBCwaxD9bYpOuDPpj7lr3Y1JLm5zAeCvFfZcERRel9n-A-9D83l1xDfmUoQPqCSbKUXwuKJA6PxfN9wsX5TfEGPbV4JLuTENdj9UtIRSuUHQMqc1Is4PVLUmoF2bKe82XjNFCo</wp:BackgroundImage> <wp:Count>12</wp:Count> <wp:Title>New App Title</wp:Title> </wp:Tile> </wp:Notification>
Anatomy of a Bug
So i really wanted to be able to dig down using Reflector to debug the library binary in real-time and show you the culprit code. Sadly this is not an easy task as Reflector is unable to debug Windows Phone 7 emulator apps as it requires Reflector being able to place a PDB file inside the emulator and currently the boffins at Red Gate are yet to solve this issue.
I could continue to review the decompiled code inside the Microsoft.Phone binary, however if i am successful with this I’ll leave it for a follow up post.
But wait there’s more
I have created a sample project that shows this issue by throwing an exception when you fire a sample URL the size of the above. This uses my previously example of allowing a phone to send itself an instant tile update. Run it in debug mode to experience all the fun!