Can't De-serialize a data structure

Hi, experts -

I'm a bit new with .Net, but pretty advanced with vb6. What I'm trying to do is take a user defined data structure and serialize/deserialize it. Serialization code is:
            Dim fs As New FileStream(ConnectionInfoFileName, FileMode.Create)
            ' Construct a BinaryFormatter and use it to serialize the data to the stream.
            Dim formatter As New BinaryFormatter
            NewObject = CType(ConnectionInfo, ConnectInfo)

            formatter.Serialize(fs, NewObject)

This seems to work - at least, the file is created and what isn't binary gibberish looks like the various names of the data structure members. (Incidentally, all members of the struct are 'Friend', not 'Public')

De-serialization looks like this:
            Dim fs As New FileStream(ConnectionInfoFileName, FileMode.Open)
            ' Construct a BinaryFormatter and use it to serialize the data to the stream.
            Dim formatter As New BinaryFormatter
            NewObject = CType(formatter.Deserialize(fs), ConnectInfo)

This consistently throws an exception 'Can't find assembly .....'
1) Is it in fact possible to serialize a struct with variable length felds?
2) If so, can you tell me what I'm doing wrong?

Thanks
LongDaveAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jayadev NairApplication DeveloperCommented:
I believe you do not have the assembly reference where you are trying to deserialize the object. Try adding reference to the dll where the actual structure is defined (if serialization & deserialization occurs in different assembly).
LongDaveAuthor Commented:
When I look at the error message, I believe you are correct, however, I'm not sure how I go about this. The application is a user control that I'm building, and the error occurs when I'm testing in the UserControl Test Container. Where would I find the dll you speak of and how do I create a reference to it? Thanks a lot - I think I'm almost there.
Jayadev NairApplication DeveloperCommented:

I believe you are serializing a class named 'ConnectInfo'. Where is this connectinfo Class located? I mean which project? You have to refer the output of the same dll/exe (I call ConnectInfo.dll) at the project where you are deserializing the same object. Add reference of the ConnectInfo.dll to the UserControl Test Container Project. Right Click on references Directory of Project -> Add reference -> Browse the dll/exe (ConnectInfo.dll). This will add the reference.

If you didnt change/specify any output path of ConnectInfo.dll project, find the dll/exe on the Project path\bin\debug

thanks.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LongDaveAuthor Commented:
I'll I'm trying to do is serialize a data structure. I changed things around a bit since the last response. I've now created a class called CInfo. Here is the entire thing:
******************************************************
Public Class CInfo

    <Serializable()> Public Structure EtherNetInfo
        Public RemoteIP As String       'IP of the remote system
        Public RemotePort As Integer    'remote port
        Public LocalPort As Integer     'remote port
        Public Const EtherNetPassword = "pass45733190"  'password for server card
    End Structure

    <Serializable()> Public Structure ModemInfo
        Public CommPort As Short                'number of the commport to use
        Public PhoneNumber As String            'phone number
        Public Password As String               'password
        Public CallWaitingDisable As Boolean    'see if call waiting is disabled
        Public CallWaitingString As String       'string to disable call waiting
        Public Const EtherNetPassword = "pass45733190"  'password for server card
    End Structure

    <Serializable()> Public Structure DTCCommPort
        Public CommPort As Short        'commport
        Public Password As String        'password
    End Structure

    <Serializable()> Public Structure PortOnly
        Public CommPort As Short        'commport
    End Structure

    <Serializable()> Public Structure ConnectInfo
        Public B3_Eth As EtherNetInfo       'BackBoneBus over Ethernet
        Public B3_Modem As ModemInfo        '   "          "  Modem
        Public L2_Eth As EtherNetInfo       'Link2 Card over Ethernet
        Public L2_CommPort As PortOnly      '   "    "  from a commport
        Public DTC_Modem As ModemInfo       'DTC over a modem
        Public DTC_Direct As DTCCommPort    'DTC over a commport
        Public Location As String           'save the location
        Public Reconnect As Boolean         'see if reconnect at startup
        Public ErrorLogEnableFlag As Boolean    'enable error logging
        Public CommLogEnableFlag As Boolean     'enable comm logging
    End Structure
    Public Sub New()

    End Sub
End Class
*********************************************
Note the structure 'ConnectInfo' is composed of the previous structs above it. In my
main program, I initialize this way:

    Friend ConnectionInfo As New CInfo.ConnectInfo

My project is called 'ConnectControl'. In my \Projects\bin\Debug folder the only dll that is there
is 'ConnectControl.dll'. If I load this as a reference I get:

'CInfo' is ambiguous in the namespace 'ConnectControl'.

I'm starting to feel like a bit of an idiot here :)
Thanks for helping - hope to hear from you (or another expert) soon
LongDaveAuthor Commented:
I got it working! Thanks for your help! You at least pointed me in the right direction, so I'll give you half points.

Thanks again -

Dave
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.