(De)Serialize in other applications

  • Thread starter Marco Trapanese
  • Start date
M

Marco Trapanese

Hi!

I wrote a VB.NET application that serializes my classes on a file. Each
file contains a different instance of the class (i.e. different values
of the properties). If I deserialize files from that application all
works fine.

Now, I need to deserialize them from my other applications. If I try I
get this error:

"Unable to find assembly 'ADACOS, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=754090432db5d9d1'."

Where 'ADACOS' is the name of the first application. I guess it's
looking for the original app.

How can I deserialize a class in another application?

Thanks,
Marco / iw2nzm
 
P

Phill W.

Marco said:
I wrote a VB.NET application that serializes my classes on a file. Each
file contains a different instance of the class (i.e. different values
of the properties). If I deserialize files from that application all
works fine.

Now, I need to deserialize them from my other applications. If I try I
get this error:

"Unable to find assembly 'ADACOS, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=754090432db5d9d1'."

Where 'ADACOS' is the name of the first application. I guess it's
looking for the original app.

In order to deserialise /any/ object, the process into which the object
is being loaded has to load the /definition/ of that Type and, quite
often, any custom deserialisation code that's been written to do this job.

I would recommend that you extract the serialisable class into a
separate assembly and reference that from both applications.

HTH,
Phill W.
 
M

Marco Trapanese

Phill said:
I would recommend that you extract the serialisable class into a
separate assembly and reference that from both applications.

Thanks, now I do it.
Just a question: I have a lot of serialized files created some time ago.
I need to re-serialize them once I'll make the new assembly?

Bye
Marco / iw2nzm
 
C

Cor Ligthert [MVP]

Marco,

Phil wrote it, but the clue is that you set a reference to it. (I found it
not clear that that was in fact your problem). However don't make a mistake,
in my idea is the solution from Phil too the best way.

Cor
 
M

Marco Trapanese

Cor said:
Marco,

Phil wrote it, but the clue is that you set a reference to it. (I found it
not clear that that was in fact your problem). However don't make a mistake,
in my idea is the solution from Phil too the best way.


Cor,

thanks for your answer. I've just write the new assembly and now all
works like a charm! :)

Now I'd like to deserialize the old files without recreate them... I
think I can do this with the serialization binder: I have to redirect
the deserialization to the new type I created. So:

Dim fmtGauge As BinaryFormatter = New BinaryFormatter
fmtGauge.Binder = New FooDeserializationBinder()

Dim datGauge As FileStream = New FileStream(filename, FileMode.Open)
collection = CType(fmtGauge.Deserialize(datGauge), Gauge)

[...]

NotInheritable Class FooDeserializationBinder
Inherits SerializationBinder
Public Overrides Function BindToType(ByVal assemblyName As String, ByVal
typeName As String) As Type
Return Type.GetType(???)
End Function
End Class

I don't understand what parameter I must pass to the GetType method.

Thanks to both!

Marco / iw2nzm
 
C

Cor Ligthert [MVP]

Marco,

I don't do concatination answers. Just place a new question in the group and
see who can answer this.

Cor

Marco Trapanese said:
Cor said:
Marco,

Phil wrote it, but the clue is that you set a reference to it. (I found
it not clear that that was in fact your problem). However don't make a
mistake, in my idea is the solution from Phil too the best way.


Cor,

thanks for your answer. I've just write the new assembly and now all
works like a charm! :)

Now I'd like to deserialize the old files without recreate them... I think
I can do this with the serialization binder: I have to redirect the
deserialization to the new type I created. So:

Dim fmtGauge As BinaryFormatter = New BinaryFormatter
fmtGauge.Binder = New FooDeserializationBinder()

Dim datGauge As FileStream = New FileStream(filename, FileMode.Open)
collection = CType(fmtGauge.Deserialize(datGauge), Gauge)

[...]

NotInheritable Class FooDeserializationBinder
Inherits SerializationBinder
Public Overrides Function BindToType(ByVal assemblyName As String, ByVal
typeName As String) As Type
Return Type.GetType(???)
End Function
End Class

I don't understand what parameter I must pass to the GetType method.

Thanks to both!

Marco / iw2nzm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top