Tuesday, 23 December 2008

Silverlight Parser Error: when to trust your instinct

I finished my entry into the MIX 2009 10k competition this morning - having been [dis|en]couraged by Andy's cool Flickr-based entry and reading that Robby's also entering.

After getting it running locally (and trimming the code down to 9,601 bytes) I decided to upload to a remote server for testing... and the problems began:

Unhandled Error in Silverlight 2 Application Code: 7014 Category: ParserError Message: illegal xml character File: XXXXX.xap Line: 1 Position: 3

Of course I was mystified... it "worked on my machine". Since I had stripped out so much from the C# and Xaml, I assumed it was the code, and set about 'fixing' it (despite a nagging doubt about why it worked locally).
  • I looked in App.xaml to see if I had somehow introduced invalid XML

  • I looked in Page.xaml for the same thing

  • I checked AppManifest.xml in the project for errors

  • I checked AppManifest.xaml in the XAP file as well

  • I googled and found that someone fixed a similar error by updating the <object> tag to use the current Silverlight version, but mine was already correct

  • I changed the file extension from XAP to ZAP (in case the server wasn't sending the file) - no difference

  • I verified that I could download the XAP and ZIP files directly (to confirm the server was sending them) - yes, the file downloaded successfully

  • I even managed to get a slight different error code somehow: Unhandled Error in Silverlight 2 Application Code: 5014 Category: ParserError Message: illegal xml character File: XXXXX.xap Line: 1 Position: 3
After spending longer than I care to admit, I started to doubt my sanity. I knew it was working locally. I was pretty sure there wasn't even any distinct element at "line 1 position 3" in any of the relevant Xml files. What could be different between my local and the server???

Finally it occured to me to check the XAP/ZIP file I downloaded from the server, just to see that it was the same as I uploaded... AH-HA! a clue!
The Compressed (zipped) Folder is invalid or corrupted. I FTPed another build of the XAP file up, and downloaded it again. Corrupted!

What's different between my local and the server? How the files got there! The file was being corrupted during the FTP process - possibly because I am sending a binary/zip format using TEXT FTP mode (not intentionally, by the way)?
It took about 2 seconds to confirm that changing the FTP mode to I/BIN and re-uploading the XAP file fixed the problem!

If FireFTP is your favourite file transfer program, the mode is shown in the status bar - where it can also be changed by a single (and accidental) click!

Apparently Silverlight can't tell the difference between corrupted ZIP/XAP packaging and a corrupted file within it; or else the error messages don't explain that very well. If you are getting this error, my first advice is to double-check your FTP settings; drop back to the command-prompt if necessary to ensure you are using the binary mode for file transfer. In fact, whenever you're FTPing, make sure you are using the correct mode!

BTW, the 10k entry isn't anything exciting - not a game and not animation driven - but it was fun nevertheless so I'll submit it and see what happens. More to come (including a plea for 'votes') when it appears on the MIX Gallery.

No comments:

Post a Comment