While working with clsClaim (which inherits from clsGenericCollection(Of clsNCPDP)) on the Billing Screen, I was receiving the following error when deserializing:
The ObjectManager found an invalid number of fixups. This This usually indicates a problem in the Formatter.
The issue here is that, when binary serialization occurred, the object type was saved with the binary data. In this case, the object type was Classes.clsGenericCollection`1[Classes.clsNCPDP]. When deserialization occurs, the object type is attempted instantiated. Because we changed namespaces, this object is no longer valid.
The solution was to create a SerializationBinder object that dictates which type to bind to. The interesting code is:
Public
Overrides
Function BindToType(ByVal assemblyName As
String, ByVal typeName As
String) As System.Type
If typeName.Contains("Classes.clsNCPDP") Then
typeName = typeName.Replace("Classes.clsNCPDP", "BioWoRx.BusinessLogic.clsNCPDP")
End
If
If typeName.Contains("Classes.clsGenericCollection") Then
typeName = typeName.Replace("Classes.clsGenericCollection", "BioWoRx.BusinessLogic.clsGenericCollection")
End
If
Return Type.GetType(String.Format("{0}, {1}", typeName, assemblyName))
End
Function
This code is used in the application like so:
theFormatter.Binder = New GenericCollectionOfNcpdpBindingRedirect()
claim_fields = CType(theFormatter.Deserialize(theStream), clsGenericCollection(Of clsNCPDP))
No comments:
Post a Comment