CRM 2013:在沙盒插件中反序列化

时间:2014-10-17 21:25:37

标签: plugins crm dynamics-crm-2013

我有一个XML字符串,我想将其反序列化为强类型类。下面的代码工作得很好,直到我把它放入一个沙盒插件,此时我得到一个FileIOPermissions错误,因为我使用的是StringReader类。我在尝试反序列化时遇到问题而不使用StringReader。有没有人有一个很好的选择?

byte[] binary = Convert.FromBase64String(configurationWebResource.Attributes["content"].ToString());
resourceContent = UnicodeEncoding.UTF8.GetString(binary);

DataContractSerializer serializer = new DataContractSerializer(typeof(ViewSecurityConfiguration));

using (StringReader reader = new StringReader(resourceContent))
{
    using (XmlTextReader xmlReader = new XmlTextReader(reader))
    {
        if (serializer.IsStartObject(xmlReader))   //Throws FileIOPermissions error
        {
            currentViewSecurityConfiguration = (ViewSecurityConfiguration)(serializer.ReadObject(xmlReader));
        }
    }
}

1 个答案:

答案 0 :(得分:0)

尝试以下我在沙盒插件中成功运行的内容:

byte[] binary = Convert.FromBase64String(configurationWebResource.Attributes["content"].ToString());
resourceContent = UnicodeEncoding.UTF8.GetString(binary);

XmlSerializer serializer = new XmlSerializer(typeof(ViewSecurityConfiguration));

using (StringReader reader = new StringReader(resourceContent))
{
    currentViewSecurityConfiguration = (ViewSecurityConfiguration)serializer.Deserialize(reader);
}