views:

1089

answers:

2

I'm working on Silverlight application that needs to display complex 2d vector graphics. It downloads zipped XAML file from the server, parses it (XamlRead) and injects to the layout root on the page. This works fine for fairly small xaml files. The problems is that I need to make it work with much bigger file (lots more content in it). For example one of my uncompressed xaml files is 20 MB large and XamlRead method takes tool long to parse it. My question is if is there a way to do all the parsing on the server side. It would best to just store serialized binary output of XamlRead method as BLOB in the database. However when I try to serialize it, I'm getting a message that "Canvas object is not marked as serializable". I will really appreciate any advices .

+1  A: 

Silverlight doesn't have much binary serialization built in; however, protobuf-net works on Silverlight and may help plug this gap. In the current build you can only really serialize types you control (due to adding attributes) - however, I'm in the middle of a big refactor to (among other things) add support for serializing types without attributes.

I expect it to be about 2 more weeks before this is available as a (hopefully) stable build, but you're welcome to take a look at it then.

Note that you will still need to give it some help (telling it what you want it to serialize), but it may be useful.

In particular, the data format ("protocol buffers") is designed to be both dense and efficient to process, which should increase the parse speed. See here for more (numbers are from main .NET, not Silverlight)

Marc Gravell
A: 

If parsing is really the problem, it might help to use pre-compiled XAMLs called 'BAML'. This is a binary representation of the XAML file. Since the binary format has a much much cheaper parser instead of the too generic XML, this helps a lot. BAML is also used internally by the .NET compiler to generate more compact files.

For more information, see also http://stuff.seans.com/2008/07/13/hello-wpf-world-part-2-why-xaml/

Rutger Nijlunsing