Chris
Chris

Reputation: 3162

Serialization of XML in Silverlight 5

I have a bit of a quandry on my hands which hopefully you can help with.

I've been developing a Silverlight application for a client in Silverlight 4. However it became apparent that I needed to have a button to allow for full screen mode. This was fine and dandy, but when in full screen mode Silverlight 4 disables most of your keyboard inputs for security reasons....... so the reason of going full screen to make entering data into the ChildWindowForms easier then became pointless.

I should point out I can't make this application out of browser due to it having to sit inside Dynamics CRM 2011 to get the context and record id it is sitting on.

Thus began my forray into silverlight 5. This version allows for applications to run in-browser in Elevated trust mode. Previously only available as an out of browser mode.

All was going great, i had figured out that I needed to get a certificate to sign my code, add some registry keys and the user to add a certificate to trusted publishers and got it working. Awesome.

My problem arose when i tried to run my application and i got an exception like this:

There is an error in XML document (1, 41). ---> System.TypeAccessException: 
Attempt by security transparent method to access security critical type failed.

At this point, all that had changed code wise was I had signed my projects with a certificate.

It seems that in Silverlight 5 It doesn't "trust" the XmlSerializer object I'm using to read in some XML configuration and deserialize into a .Net Object

After some digging it seems theres a new Serializer in town to do this for Silverlight 5, the DataContractSerializer So i thought, great I can just ammend some of the serialization code and all will be fine. Sadly not the case.

It seems that this version of the Serializer is 33% quicker in this version. The reason it is quicker, is all nodes in the XML must be in alphabetical order. If they are not in this order they are read in as null. (If they happen to be in the correct position they will be read in correctly though. )

So my question is this. Do I have no choice but to reorganize all my XML configuration files into alphabetical order to adapt to this new Serialzer, or is there a way to use the old XML serializer and make Silverlight 5 trust it?

Upvotes: 1

Views: 1007

Answers (1)

AnthonyWJones
AnthonyWJones

Reputation: 189505

First of all the DataContractSeriailiser isn't new to Silverlight 5 it was there before.

The nodes being in alphabetical order is, I believe, a default. The DataMemberAttribute which you can attach to each property being serialised has a Order property which you can use to dictate the order they appear in.

Upvotes: 1

Related Questions