简体   繁体   English

Silverlight 5中的XML序列化

[英]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. 我一直在为Silverlight 4中的客户端开发Silverlight应用程序。但是很明显,我需要有一个按钮才能允许全屏模式。 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. 这很好而且很花哨,但是出于安全原因,在全屏模式下,Silverlight 4会禁用大多数键盘输入.......因此,全屏显示以便更轻松地将数据输入到ChildWindowForms中的原因变得毫无意义。

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. 我应该指出,由于必须将其放置在Dynamics CRM 2011中才能获取上下文并记录其所在的ID,因此无法从浏览器中制作该应用程序。

Thus began my forray into silverlight 5. This version allows for applications to run in-browser in Elevated trust mode. 因此,我的求助开始进入silverlight5。此版本允许应用程序在浏览器中以高权限信任模式运行。 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 似乎在Silverlight 5中,它不“信任”我用来读取某些XML配置并反序列化为.Net对象的XmlSerializer对象。

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. 经过一番挖掘之后,看来似乎有一个新的Serializer可以为Silverlight 5, DataContractSerializer做到这一点,所以我想,很好,我可以修改一些序列化代码,一切都会好起来的。 Sadly not the case. 不幸的是事实并非如此。

It seems that this version of the Serializer is 33% quicker in this version. 看来此版本的序列化程序在此版本中的速度提高了33%。 The reason it is quicker, is all nodes in the XML must be in alphabetical order. 之所以更快,是因为XML中的所有节点都必须按字母顺序排列。 If they are not in this order they are read in as null. 如果它们不按此顺序排列,则将它们读为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? 我别无选择,只能将我的所有XML配置文件重新组织为字母顺序以适应此新的Serialzer,还是有办法使用旧的XML序列化程序并使Silverlight 5信任它?

First of all the DataContractSeriailiser isn't new to Silverlight 5 it was there before. 首先,DataContractSeriailiser在Silverlight 5中并不陌生。

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. 可以附加到要序列化的每个属性的DataMemberAttribute具有Order属性,可以使用该属性来指示它们出现的顺序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM