Compressed Assets in Silverlight.
Posted by caseyrayl on June 8, 2007
You might have noticed that XAML files can get massive, much larger than a corresponding SWF file to represent the given vector art and animations. The solution to this that I found was posted over at Tim Huers blog. The code Tim posted is for JavaScript, but I found that the process works equally well in managed C#. Basically you can wrap all of your assets up into a zip archive, pull the archive down from the server at runtime, extract what you need from it and display it dynamically.
The process worked well with one caveat. Certain png files that existed in my application would not load at runtime from code. You could link them in the xaml and they worked properly, but when loaded at runtime threw a COM exception. I tested plain old xml, xaml, jpg, and wmv files without a problem. Even 25% of my png files worked properly. Some had transparency, some didn’t, and I was not able to discern a pattern.
In spite of the png compatibility issue, I think zip archives are definitely the way to go when pulling down remote assets. Visual Studio gives you the ability to embed any asset you want directly into the assembly, but it does not compress them. What would be ideal is if the assets embedded into the dll were compressed internally and the archiving was totally abstracted from the application programmer, but until Microsoft decides they want to do that, using a zip archive to house assets is the next best thing.
-Casey