Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Ok here I have found something. :)</p> <p><a href="http://techdigger.wordpress.com/2007/12/22/deserializing-data-into-a-dynamically-loaded-assembly/" rel="nofollow noreferrer">http://techdigger.wordpress.com/2007/12/22/deserializing-data-into-a-dynamically-loaded-assembly/</a></p> <p>I used this approach and it worked without any problem.</p> <p>Firs defined a binder class:</p> <pre><code> internal sealed class VersionConfigToNamespaceAssemblyObjectBinder : SerializationBinder { public override Type BindToType(string assemblyName, string typeName) { Type typeToDeserialize = null; try{ string ToAssemblyName = assemblyName.Split(',')[0]; Assembly[] Assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly ass in Assemblies){ if (ass.FullName.Split(',')[0] == ToAssemblyName){ typeToDeserialize = ass.GetType(typeName); break; } } } catch (System.Exception exception){ throw exception; } return typeToDeserialize; } } </code></pre> <p>And then serialization methods:</p> <pre><code> public static byte[] Serialize(Object o){ MemoryStream stream = new MemoryStream(); BinaryFormatter formatter = new BinaryFormatter(); formatter.AssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple; formatter.Serialize(stream, o); return stream.ToArray(); } public static Object BinaryDeSerialize(byte[] bytes){ MemoryStream stream = new MemoryStream(bytes); BinaryFormatter formatter = new BinaryFormatter(); formatter.AssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple; formatter.Binder = new VersionConfigToNamespaceAssemblyObjectBinder(); Object obj = (Object)formatter.Deserialize(stream); return obj; } </code></pre> <p>And I use them where I need.</p> <pre><code> protected void SaveAsBinary(object objGraph, string fileName) { byte[] serializedData = Serialize(objGraph); File.WriteAllBytes(fileName, serializedData); } protected object LoadFomBinary(string fileName) { object objGraph = null; try { objGraph = BinaryDeserialize(File.ReadAllBytes(fileName)); } catch (FileNotFoundException fne) { #if DEBUG throw fne; #endif } return objGraph; } </code></pre> <p>Thanks for help :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload