views:

20

answers:

0

Howdy,

I have some data which was serialized to bin using a different assembly, per company policy.

Now this same data needs to be read by another application which obviously, has a different assembly. This poses a problem since the other application, which we can call as Assembly2, cannot read the data file, Leibniz_Notation.bin, since the .bin file has in it's header Assembly1.

I've looked at the sample function/class provided at MSDN, as follows :

NotInheritable Class Version1ToVersion2DeserializationBinder Inherits SerializationBinder Public Overrides Function BindToType(ByVal assemblyName As String, _ ByVal typeName As String) As Type

  Dim typeToDeserialize As Type = Nothing

  ' For each assemblyName/typeName that you want to deserialize
  ' to a different type, set typeToDeserialize to the desired type.
  Dim assemVer1 As String = [Assembly].GetExecutingAssembly().FullName
  Dim typeVer1 As String = GetType(Version1Type).FullName

  If assemblyName = assemVer1 And typeName = typeVer1 Then
     ' To use a type from a different assembly version, 
     ' change the version number.
     ' To do this, uncomment the following code.
     ' assemblyName = assemblyName.Replace("1.0.0.0", "2.0.0.0")

     ' To use a different type from the same assembly, 
     ' change the type name.
     typeName = typeName.Replace("Version1Type", "Version2Type")

  Else

    assemblyName = ???
    typeName = ???

  End If

  ' The following code returns the type.
  typeToDeserialize = Type.GetType(String.Format("{0}, {1}", typeName, _
                                   assemblyName))

  Return typeToDeserialize

End Function End Class

My question is, the class provides for a mechanism for deserialization provided the assemblies are the same, even if the serialized class/data differed in structure. What I needed to know is what if the assemblies are different; how will I trick the DeSerialize routine into thinking that the Assembly2 is just Assembly1 ?

Any advise is greatly appreciated. Thanks.