I am trying to deserialize a custom object that has been previously serialized and saved in a file. and I have the following code:
The problem is the linePHP Code:If open.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim fs As FileStream = New FileStream(open.FileName, FileMode.Open)
Try
testing = New ItemInfo
Dim formatter As New BinaryFormatter
Dim obj As Object = formatter.Deserialize(fs)
testing = DirectCast(obj, ItemInfo)
Catch ex As Exception
MsgBox(ex.Message)
Finally
fs.Close()
End Try
End If
I am getting an exception:PHP Code:testing = DirectCast(obj, ItemInfo)
I have verified that the variable testing and obj are actually instantiated. That leaves ItemInfo which is the name of my custom type (Not an instance of the class).Object not set to an instance of an object
Since the variable testing and obj are instantiated it seems like it does not like the reference to the class ItemInfo.
What could I be doing wrong here?




Reply With Quote
