Results 1 to 7 of 7

Thread: Runtime Exception: "is not marked as serializable."

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Posts
    28

    Default Runtime Exception: "is not marked as serializable."

    I am facing an error. I created a Table

    
       Public sessionTable As XTable(Of String, Object) = Nothing
        sessionTable = sessionDB.Scheme.CreateOrOpenXTable(Of String, Object)(New Locator("EntryHashTable"))
    
    Type 'LibertyPIMLib.GenericCategoriesStructure' in Assembly 'LibertyPIMLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0653eac2cb2bb1b9' is not marked as serializable.

    I inserted some objects of GenericCategoriesStructure Class. Now I am getting runtime exceptions that the Class is not serializable. I wrote the <Serializable()> _ above the class, but then I received more errors like unable to create table based on this class.

    Is there a way that I am able to insert the Class object into the XTable<Of String, Object> without writing Serializable attribute? I only want is that no exception comes and that I could be able to store and restore back the objects.

  2. #2

    Default

    When you define a table with record of type object
        XTable<string, object> table;
    
    the table creates a SerializableIndexerPersist<object> instance to store and load the records for it.
    public class SerializableIndexerPersist<T> : IIndexerPersist<T>
    
    This persist implementation stores the table rows by serializing it with a standart BinaryFormatter. Therefore such tables require a serializable objects.

    I wrote the <Serializable()> _ above the class, but then I received more errors like unable to create table based on this class.
    What is the LibertyPIMLib.GenericCategoriesStructure definition? Does it really a serializable class?

  3. #3
    Junior Member
    Join Date
    Apr 2011
    Posts
    28

    Default I did not put Serializable attributes on all the required Classes.

    Quote Originally Posted by a.todorov View Post
    When you define a table with record of type object
        XTable<string, object> table;
    
    the table creates a SerializableIndexerPersist<object> instance to store and load the records for it.
    public class SerializableIndexerPersist<T> : IIndexerPersist<T>
    
    This persist implementation stores the table rows by serializing it with a standart BinaryFormatter. Therefore such tables require a serializable objects.


    What is the LibertyPIMLib.GenericCategoriesStructure definition? Does it really a serializable?

    There are parent classes which are inherited by GenericCategoriesStructure Class. I was missing Serializable attribute on all the parent classes, and on GenericCategoriesStructure Class. so it caused run time exceptions. When I put Serializable on all the classes which are stored in the Database, the problem went away. And I was also trying to store TreeNode Objects in the Database. The TreeNodes got stored but they lost the properties given by the TreeView Control. Well, its ok now. This attribute is required when I use XTable<string, object>.
    Last edited by aroratushar; 05.05.2011 at 21:00. Reason: missing lines.

  4. #4
    Junior Member
    Join Date
    Apr 2011
    Posts
    28

    Default

    Now a new runtime exception is coming. Maybe it's a bug because I can't modify the BlobStream Class which is coded in the dll. I wrote serializable attributes to all the classes which are required to be stored in the DB. There are BlobStream objects in a one or two Classes. If there's any solution, please help.

    {System.Runtime.Serialization.SerializationExcepti on: Type 'STSdb.Files.BlobStream' in Assembly 'STSdb, Version=3.5.9.0, Culture=neutral, PublicKeyToken=0653eac2cb2bb1b9' is not marked as serializable." & vbCrLf & " at System.Runtime.Serialization.FormatterServices.Int ernalGetSerializableMembers(RuntimeType type)" & vbCrLf & " at System.Runtime.Serialization.FormatterServices.Get SerializableMembers(Type type, StreamingContext context)" & vbCrLf & " at System.Runtime.Serialization.Formatters.Binary.Wri teObjectInfo.InitMemberInfo()" & vbCrLf & " at System.Runtime.Serialization.Formatters.Binary.Wri teObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)" & vbCrLf & " at System.Runtime.Serialization.Formatters.Binary.Obj ectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo)" & vbCrLf & " at System.Runtime.Serialization.Formatters.Binary.Obj ectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)" & vbCrLf & " at System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)" & vbCrLf & " at System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.Serialize(Stream serializationStream, Object graph)" & vbCrLf & " at STSdb.Persist.SerializableIndexerPersist`1.Store(B inaryWriter writer, IIndexer`1 values)" & vbCrLf & " at STSdb.Data.DefaultBinaryPersist`1.Store(BinaryWrit er writer, IIndexer`1 data)" & vbCrLf & " at STSdb.Data.FTable`2.CollapsedCollection.Save(Memor yStream stream)" & vbCrLf & " at STSdb.Data.FTable`2.Link.Save()" & vbCrLf & " at STSdb.Data.FTable`2.Flush()" & vbCrLf & " at STSdb.Data.FTable`2.Commit()" & vbCrLf & " at STSdb.Data.XTable`2.Commit()" & vbCrLf & " at LibertyPIMLib.LibertyPIMVaultEntry.InsertVaultEntr iesInDB(LibertyPIMJournal& session, ArrayList& arrayEntries) in L:\Project - LibertyPIM\LibertyPIM\LibertyPIM\sub-projects\LibertyPIMLib\LibertyPIMVaultEntry.vb:lin e 141}

  5. #5

    Default

    Can you post a test code, which reproduce the runtime error?

  6. #6
    Junior Member
    Join Date
    Apr 2011
    Posts
    28

    Default BlobStream Object is giving not serializable exception when put in serializable class

    The Runtime exception is surely a bug as I copied the code in a simple form in a new application and still the runtime exception always comes and commit action fails. If I make a Class which is to be stored in the Database, as serializable. And when I put a BlobStream object into that Class, the XTable.Commit fails and returns a run-time exception. However the data is copied into the Database by BlobStream. Still the new Class instance fails to store. I created a demo application and inserted some code. I found out it as a bug, and not my fault. Even though my classes are marked as serialization, but the BlobStream Class which exists in the stsdb.dll, is not marked as Serialization, and so the run time exception comes. It might be possible that if there are other Classes like BlobStream in the stsdb.dll, even those classes may give the run-time exception. Here it is:

    
    Imports STSdb.Data
    Imports STSdb.Files
    Imports System.IO
    
    Public Class Form1
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            BlobStreamClass1.InsertStoredFileEntriesInDB()
        End Sub
    End Class
    
    
    
    <Serializable()> _
    Public Class BlobStreamClass1
    
        ' This class instance stores the handle and other information regarding the stored file.
        Public Property StoredFilename As String = "" ' This is the original filename of this File entry.
        Public Property StoredFileHandle As ULong = 0 ' File handle in Database
        Public Property StoredFileOffset As ULong = 0 ' 
        Public Property StoredFileLength As ULong = 0 ' Stored File Length
        Public Property StoredFilePath As String = "" ' the full path and filename of the stored file
    
        Public Property data As BlobStream = Nothing 'STSdb.Files.BlobStream = Nothing
    
    
        Public Shared Function InsertStoredFileEntriesInDB() As Boolean
            Dim boolResult As Boolean = False
    
            ' Open the XTable
            Dim srcTable As XTable(Of Long, BlobStreamClass1) = Nothing
    
            Dim db As StorageEngine = StorageEngine.FromFile("C:\tmp.stsdb")
    
            Try
                srcTable = db.Scheme.CreateOrOpenXTable(Of Long, BlobStreamClass1)(New Locator("BlobStreamClass1"))
            Catch ex As Exception
                Return False
            End Try
    
            Try
    
                ' Get a new valid unused key
                Dim newKey As Long = 0
    
                ' Initialize objects
                Dim rawFile As RawFile = Nothing
                '                Dim myOutputBlobStream As BlobStream = Nothing
                Dim myOutputBlobStream As BlobStream = Nothing
    
                Try
                    rawFile = db.FileSystem.CreateFile() 'srcTable.RawFile.FileSystem.CreateFile() 'srcTable.RawFile
                Catch ex As Exception
                    GoTo ErrorOccured ' Critical error, cannot open the RawFile/BlobStream, maybe some serious error, so abort
                End Try
    
                Try
                    '                    myOutputBlobStream = New BlobStream(rawFile, rawFile.Length, inputEntry.StoredFileLength) 'fsInput.Length) '10 * 1024 * 1024)
                    myOutputBlobStream = New BlobStream(rawFile, rawFile.Length, New FileInfo("L:\test1.zip").Length)
    
                Catch ex As Exception
                    GoTo ErrorOccured
                End Try
    
                Dim cBlobStreamClassInstance As New BlobStreamClass1()
                cBlobStreamClassInstance.data = myOutputBlobStream
                cBlobStreamClassInstance.StoredFileHandle = rawFile.Handle
    
                ' Finally copy the data
                Dim fileSize As ULong = 0
                If Not CopyFileToStream("L:\test1.zip", myOutputBlobStream, fileSize) Then GoTo ErrorOccured
    
                srcTable(newKey) = cBlobStreamClassInstance
                srcTable.Commit() ' Commit the data
    
            Catch ex As Exception
                GoTo ErrorOccured
            End Try
    
            ' Done
            GoTo Success
    
    ErrorOccured:
            boolResult = False
            GoTo Finished
    Success:
            boolResult = True
            GoTo Finished
    
    Finished:
            If Not IsNothing(srcTable) Then srcTable.Close()
    
            ' Success
            Return boolResult
        End Function
    
    
        Public Shared Function CopyFileToStream(ByVal inputFilePath As String, ByRef output As Stream, Optional ByRef outputFileSize As ULong = Nothing) As Boolean
            Dim boolResult As Boolean = False
    
            If IsNothing(output) Then Return False
            If inputFilePath.Length <= 0 Then Return False
            Dim fsInput As FileStream = Nothing
    
            Try
                ' Open the source file for streaming
                fsInput = New FileStream(inputFilePath, FileMode.Open, FileAccess.Read)
            Catch ex As Exception
                Return False
            End Try
    
            ' Set the file size to the output variable
            outputfileSize = fsInput.Length
    
            Dim buffer(32768) As Byte
            Try
                While True
                    Dim read As Integer = fsInput.Read(buffer, 0, buffer.Length)
                    If read <= 0 Then Exit While
                    output.Write(buffer, 0, read)
                    output.Flush()
                End While
            Catch ex As Exception
                GoTo ReturnError
            End Try
    
            GoTo ReturnSuccess
    ReturnError:
            boolResult = False
            GoTo Finished
    ReturnSuccess:
            boolResult = True
            GoTo Finished
    Finished:
    
            If Not IsNothing(fsInput) Then
                Try
                    fsInput.Close()
                    fsInput.Dispose()
                Catch ex As Exception
                End Try
            End If
    
            Return boolResult
        End Function
    
    End Class
    

  7. #7

    Default

    Yes, you are right, there is an issue with the BloblStream class in 3.5.9 - it must be marked as serializable.

    In general, when you define table of type
        XTable<TKey, object> table;
    
    or when you define table of type
        XTable<TKey, TRecord> table;
    
    where TRecord is marked as serializable - in both cases the XTable uses a SerializableIndexerPersist<T> instance to store the records with standart .NET BinaryFormatter. And if the object (first case) or the record (second one) contain a BlobStream field/property, the SerializableIndexerPersist instance is unable to serialize it.

    In your code above, if you remove the serializable attribute from the BlobStreamClass1 declaration, the example should be working without problems - the engine will generate a special persist code for the BlobStreamClass1 class and will use it, to correctly store the records in vertical mode. But if you want to explicitly store objects marked as serializable, which have BlobStream properties (as in your example), the engine will throw an exception.

    We will fix this issue in the next release.

    Thank you for your report!

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
  •  
2002 - 2014 STS Soft SC. All Rights reserved.
STSdb, Waterfall Tree and WTree are registered trademarks of STS Soft SC.