Serialize
-
Hi! I'm trying to open a file with a serialized (binary) arraylist. The problem is that the application in which I save the data saves the assemblyname in the file, so when I try to open the file in another application whith another name, it throws an exception. System.Runtime.Serialization.SerializationException. There's probably an easy way to solve this but I'm rather new at this so... Thanx Andreas Färnstrand
-
Hi! I'm trying to open a file with a serialized (binary) arraylist. The problem is that the application in which I save the data saves the assemblyname in the file, so when I try to open the file in another application whith another name, it throws an exception. System.Runtime.Serialization.SerializationException. There's probably an easy way to solve this but I'm rather new at this so... Thanx Andreas Färnstrand
throw in some of your code you used to save the serialized arraylist. i have my serialize class wrote with this code.. among others. this will fill the memorystream and return its byte[] MemoryStream memstr = new MemoryStream(); BinaryFormatter formatter =new BinaryFormatter(); formatter.Serialize(memstr,MyObjectHere); return memstr.ToArray(); to save it i call this. Stream fs= File.Create(path); byte[] tmp = \*(The Byte Array From Above here)*\ memstr.ToArray(); fs.Write(tmp,0,tmp.Length); //the serialized object is wrote now. to open it stream= File.Open(path,FileMode.Open); // BinaryFormatter bf = new BinaryFormatter(); Object =(CastingObjectHere)bf.Deserialize(stream); hope this helps, if not. someone older and wiser will help u =) The Code Project Is Your Friend...
-
Hi! I'm trying to open a file with a serialized (binary) arraylist. The problem is that the application in which I save the data saves the assemblyname in the file, so when I try to open the file in another application whith another name, it throws an exception. System.Runtime.Serialization.SerializationException. There's probably an easy way to solve this but I'm rather new at this so... Thanx Andreas Färnstrand
What you need is a SerializationBinder for the new assembly. See the sample code on MSDN for System.Runtime.Serialization.SerializationBinder for something similar to what you want... Yes, even I am blogging now!