[Mono-dev] Problem with BinarySerialization

PFJ pjohnson1 at uclan.ac.uk
Tue Feb 2 08:35:16 EST 2010


Hi,


Robert Jordan wrote:
> 
>> What I have done is created a completely different app to generate the
>> serialized data - it's intended to be run once, create the data file and
>> that's it.
>>
>> The file is then sucked in to the 2nd application for deserializing.
>> Would
>> what I want to do be better using an Xml serialized file or will I hit
>> the
>> same problem? Failing that I'm guessing I'll need to draw the file into a
>> list (more or less the reverse of creating the list in the first place).
> 
> You won't hit the same problem but you'd still have to duplicate
> Elements code.
> 
> Thus, the only *clean* way to solve this is introducing a shared
> assembly implementing the classes you want to serialize. It's a
> common pattern.
> 

As the serializer is only used once, can the other app just deserialize and
use it? I've reimplemented the Elements class but now just have a little
problem in accessing it...

New code

		public void dotheread()
		{
			try 
			{
				string path_env = Path.GetDirectoryName(Application.ExecutablePath) +
Path.DirectorySeparatorChar;
				Stream stream = File.Open(path_env + "elements.ele", FileMode.Open);
				BinaryFormatter bf = new BinaryFormatter();
				var elementgo = new List<Elements>();
				elementgo = (Elements)bf.Deserialize(stream);
				stream.Close();
			}
			catch(System.IO.FileNotFoundException)
			{
				MessageBox.Show("Unable to find the elements information file", "File
not found", MessageBoxButtons.OK);
			}
		}

Problem is the casting of the class to deserialize - it's not an object so
can't use it and something like Elements el = new Elements(); isn't cutting
it either...

TTFN

Paul
-- 
View this message in context: http://old.nabble.com/Problem-with-BinarySerialization-tp27419333p27420438.html
Sent from the Mono - Dev mailing list archive at Nabble.com.



More information about the Mono-devel-list mailing list