Results 1 to 5 of 5

Thread: [RESOLVED] Serialization done in DLL won't work in 2nd pgm

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2010
    Posts
    28

    Resolved [RESOLVED] Serialization done in DLL won't work in 2nd pgm

    I've written one pgm that used byte serialization to save a file. It eventually morphed into a program and a library class (dll) so I could save/retrieve the byte serialization/desrerialization file from a different program that would use the same dll that originally serialized file in the first program.
    But, the first program seems to own the serialized file, not the DLL. The first progam is GenerateEventList and has the added reference Imports EventDBS which is the DLL. The second program EventDisplay also has Imports EventDBS to read the file. It produces the exception:
    Code:
    Failed: Unable to find assembly 'GenerateEventList ...'
    Is this a build error, do the two programs and the dll need to reside in the same folder or folders?

    Any advice would be appreciated.

  2. #2
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: Serialization done in DLL won't work in 2nd pgm

    Does the dll contain a reference to the first application?
    This could be a code reference, a namespace or resources etc.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Dec 2010
    Posts
    28

    Re: Serialization done in DLL won't work in 2nd pgm

    Thanks Merrion. I'm new to VS2010 so I 'm not sure how to check some of your suggestions.

    Code references: I think i've checked - the code for EvnetDBS.vb code (the DLL) has no references to GenerateEventList in the code.
    Namespace: I have no clue about namespace: what it does, how I check it, its use - nothing.
    Resources: Not sure here either what to check for this.

    Maybe I haven't declared the DLL properly in the program code?
    To include a DLL reference in my program code I have:
    0.) Added code: Imports EventDBS in the program code
    1.) "Add reference... EventDBS", but in order to get some of the errors to disappear in the code I also had to
    2.) "Add an existing item... which again was the EventDBS.vb

    May be I haven't written the DLL (EvenetDBS.vb) code properly,
    Code:
    Imports System.IO
    Imports System.Runtime.Serialization
    Imports System.Runtime.Serialization.Formatters.Binary
    
    Public Class EventDBS
    
        <Serializable()> Public Structure EventRec
            Dim EventDate As Date
            Dim AckDate As Date
            Dim EventType As Integer
            Dim Color As Integer
            Dim Freq As Integer
            <VBFixedString(256)> Public Desc As String
        End Structure
    
        Const BIN_FILE_NAME As String = "EventList"
        Public BIN_PATH_FILE As String = "D:" & "\" & BIN_FILE_NAME  'Environment.CurrentDirectory() 
        Public EventArray(1000) As EventRec
    
        Public Sub WriteDatFile()
            Dim bf As New BinaryFormatter
    
            Using fs As New FileStream(BIN_PATH_FILE, FileMode.Create)            
                Try
                    bf.Serialize(fs, EventArray)
                Catch ex As SerializationException
                    MsgBox("Failed: " & ex.Message)
                    Throw
                End Try
            End Using
    
        End Sub
    
        Public Sub ReadDatFile()
            Dim bf As New BinaryFormatter
    
            Using fs As New FileStream(BIN_PATH_FILE, FileMode.Open)
                Try
                    EventArray = bf.Deserialize(fs)
    
                Catch ex As Exception
                    MsgBox("Failed: " & ex.Message)
                    Throw
                End Try
            End Using
        End Sub
    End Class
    Maybe some of the Assembly Information for EventDBS is wrong?
    Code:
    Title: ClassLibrary1 <= should this be changed to EventDBS?
    Description: <empty>
    Company: Microsoft
    Product: ClassLibrary1 <= should this be changed to EventDBS?
    Copyright: Micosoft 2010
    Trademark: <empty>
    Assembly Version: 1000
    File Version: 1000
    GUID: 91513d07-fc1b-4920-9848-b3768dd46a12 <= is this somehow connected?
    Neutral Language: (None)
    Last edited by n_minus_one; Jan 1st, 2011 at 02:26 PM.

  4. #4

    Re: Serialization done in DLL won't work in 2nd pgm

    Is the serializable structure in the DLL? If so, both programs need to reference the exact same DLL for it to work.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Dec 2010
    Posts
    28

    Re: Serialization done in DLL won't work in 2nd pgm

    Thanks Merrion! It indeed was the Namespace giving me grief. What was curious is that the Assembly name also needed to be identical. Hmm, lots of literature about Namespace, not so much about Assembly Names.

    I'm thinking that the next project should have all it's programs and dlls in the same folder.

    I really appreciate pointing me in the right direction!

    Thanks formlesstree4. Your avatar is hilarious.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width