Re: [Mono-dev] Problem with BinarySerialization

2010-02-03 Thread Robert Jordan
On 03.02.2010 10:49, PFJ wrote:
>
> Hi,
>
>
> Robert Jordan wrote:
>>
>> On 02.02.2010 14:35, PFJ wrote:
 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...
>>
>> It doesn't matter how often, in which way or how symmetric
>> the de/serialization is performed. What counts is the type identity.
>>
>
> Hmm, I guess that is why after I've sorted out the code (thanks), added in
> the Elements class and now have it compiled, I'm getting the same error as I
> did originally (SerializationError - can't find 'elements').

Did you create a separate shared assembly or have you just
included the Elements class in both projects? The latter does
not ensure type identity and it's not what you want.

Robert

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] Problem with BinarySerialization

2010-02-03 Thread PFJ

Hi,


Robert Jordan wrote:
> 
> On 02.02.2010 14:35, PFJ wrote:
>>> 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...
> 
> It doesn't matter how often, in which way or how symmetric
> the de/serialization is performed. What counts is the type identity.
> 

Hmm, I guess that is why after I've sorted out the code (thanks), added in
the Elements class and now have it compiled, I'm getting the same error as I
did originally (SerializationError - can't find 'elements').

I'm running the debugger on the code that generates the binaryserialized
form and when I look at the debug information (I admit, this is under
VS2008) it says 

elementgo Count=111 with a plus icon before the element go. click on the +
icon and it says
+ 0 {elements.Form1.Elements}. click on the + icon and it gives me the copy
of the list.

Is it this {elements.Form1.Elements} it's objecting to?

TTFN

Paul

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

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] Problem with BinarySerialization

2010-02-02 Thread Robert Jordan
On 02.02.2010 14:35, PFJ wrote:
>> 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...

It doesn't matter how often, in which way or how symmetric
the de/serialization is performed. What counts is the type identity.

>   var elementgo = new List();

Superfluous.

>   elementgo = (Elements)bf.Deserialize(stream);

var elementgo = (List) bf.Deserialize(stream);


> 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...

See above.

Robert

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] Problem with BinarySerialization

2010-02-02 Thread PFJ

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();
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.

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] Problem with BinarySerialization

2010-02-02 Thread Robert Jordan
On 02.02.2010 14:01, PFJ wrote:
>
> Hi,
>
>
> Robert Jordan wrote:
>>
>> The serialization infrastructure heavily relies on type/assembly
>> identity, but what you're doing here is trying to create an object
>> from serialization data generated from a totally different class.
>>
>> You should implement "Elements" in a separated assembly which you
>> reference from both apps. Then, in you "Form", you should aggregate
>> Elements, i.e. make it a field, because de/serializing a Form
>> is not what you want. Really.
>>
>
> Ah
>
> 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.

Robert

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] Problem with BinarySerialization

2010-02-02 Thread PFJ

Hi,


Robert Jordan wrote:
> 
> The serialization infrastructure heavily relies on type/assembly 
> identity, but what you're doing here is trying to create an object
> from serialization data generated from a totally different class.
> 
> You should implement "Elements" in a separated assembly which you 
> reference from both apps. Then, in you "Form", you should aggregate 
> Elements, i.e. make it a field, because de/serializing a Form
> is not what you want. Really.
> 

Ah

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).

TTFN

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

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] Problem with BinarySerialization

2010-02-02 Thread Robert Jordan
On 02.02.2010 13:04, PFJ wrote:
> However, the problem comes when I try to read it back in into a different
> program. The read in code looks like this
 >
> namespace molarity
> { 
>   [Serializable()]
>   
>   public class xmlhandler : Form, ISerializable
>   {
> System.Runtime.Serialization.SerializationException: Unable to find assembly
> 'elements, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
>
> Do I need to add this into the references? I would have thought as it is an
> external file, it would just be read in via the stream method.
>
> Any ideas?

The serialization infrastructure heavily relies on type/assembly 
identity, but what you're doing here is trying to create an object
from serialization data generated from a totally different class.

You should implement "Elements" in a separated assembly which you 
reference from both apps. Then, in you "Form", you should aggregate 
Elements, i.e. make it a field, because de/serializing a Form
is not what you want. Really.

public class xmlhandler : Form
{
Elements theElements;

public xmlhandler ()
 {
theElements = deserialize them ...
 }
}

Robert


___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list