dimanche 26 mars 2017

Deserialize XML without using Assembly.reflection

So I need help with trying to deserialize a large XML file to a class. My plugin runs in a extremely locked down appdomain where I cant reference the assembly its self. How can I Deserialize my xml string. I would not like to write it all by hand.

Below is the error that is thrown

[   3380094] Error invoking callback for event onClientResourceStart: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.MethodAccessException: Error verifying System.Xml.Serialization.XmlSerializer:.ctor (System.Type,string): Method System.Reflection.Assembly:op_Equality (System.Reflection.Assembly,System.Reflection.Assembly) is not accessible at 0x00b7
[   3380094]   at System.Xml.Serialization.XmlSerializer..ctor (System.Type type) [0x00000] in <63deab55b0184b3986aa59caa8977082>:0 
[   3380094]   at ELS.configuration.VCF.load (ELS.configuration.SettingsType+Type type, System.String Data) [0x00026] in <de6203b91a5a474f9386b9994903dbe1>:0 
[   3380094]   at ELS.FileLoader.RunLoadeer (System.String name) [0x0012f] in <de6203b91a5a474f9386b9994903dbe1>:0 
[   3380094]   at ELS.ELS.<.ctor>b__5_0 (System.String obj) [0x00001] in <de6203b91a5a474f9386b9994903dbe1>:0 
[   3380094]   at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
[   3380094]   at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <a4e3abdd630b4c98a9d6f31a99197de6>:0 

The code below is the code that is throwing the error

data = new vcfroot();
Debug.WriteLine(typeof(vcfroot).ToString());
var serializer = new XmlSerializer(typeof(vcfroot));
var xmlreader = new XmlTextReader(Data);
if (serializer.CanDeserialize(xmlreader))
{
    object ddata = serializer.Deserialize(xmlreader);
}





Aucun commentaire:

Enregistrer un commentaire