Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Serialize and DeSerialize
Message
From
30/01/2014 09:58:01
 
 
To
29/01/2014 18:48:51
General information
Forum:
ASP.NET
Category:
Visual Studio
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01592595
Message ID:
01592638
Views:
44
Thank you very much for your reply.

>>Hello Everybody,
>>
>>I get the following error message when I try to run the following statement to Serialize data:
>>
>>
>>oSoapFormatter.Serialize(oFileStream, oSoapFormatter)
>>
>>
>>Type 'System.Runtime.Serialization.Formatters.Soap.SoapFormatter' in Assembly 'System.Runtime.Serialization.Formatters.Soap, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable.
>>
>>Here is the complete code:
>>
>>
>>Imports System.IO
>>Imports System.Runtime.Serialization
>>Imports System.Runtime.Serialization.Formatters.Binary
>>Imports System.Runtime.Serialization.Formatters.Soap
>>Imports System.Reflection
>>
>>Public Class Form2
>>
>>    Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
>>
>>        Dim oHashTable As New Hashtable
>>
>>        oHashTable.Add("One", 1)
>>        oHashTable.Add("Two", 2)
>>        oHashTable.Add("Three", 3)
>>
>>        SaveSoapData("C:\Users.XML", oHashTable)
>>
>>    End Sub
>>
>>    Sub SaveSoapData(ByVal sFilename As String, ByVal oObjectToSave As Object)
>>
>>        Try
>>
>>            Dim oFileStream As FileStream = New FileStream(sFilename, FileMode.Create)
>>
>>            Dim oSoapFormatter As New SoapFormatter(Nothing, New StreamingContext(StreamingContextStates.File))
>>
>>            oSoapFormatter.Serialize(oFileStream, oSoapFormatter)
>>
>>            oFileStream.Close()
>>
>>        Catch oError As Exception
>>
>>            Dim sErrorString As String
>>            sErrorString = "Message ---" & oError.Message
>>            sErrorString = sErrorString & vbCrLf
>>            sErrorString = sErrorString & "HelpLink ---" & oError.HelpLink
>>            sErrorString = sErrorString & vbCrLf
>>            sErrorString = sErrorString & "Source ---" & oError.Source
>>            sErrorString = sErrorString & vbCrLf
>>            sErrorString = sErrorString & "StackTrace ---" & oError.StackTrace
>>            sErrorString = sErrorString & vbCrLf
>>            sErrorString = sErrorString & "TargetSite ---" & oError.TargetSite.ToString
>>
>>           MessageBox.Show(sErrorString, "Error")
>>
>>            End
>>
>>        End Try
>>
>>    End Sub
>>
>>    Function LoadSoapData(ByVal sFilename As String) As Object
>>
>>        Try
>>
>>            Dim oFileStream As FileStream = New FileStream(sFilename, FileMode.Open)
>>
>>            Dim oSoapFormatter As New SoapFormatter(Nothing, New StreamingContext(StreamingContextStates.File))
>>
>>            LoadSoapData = oSoapFormatter.Deserialize(oFileStream)
>>
>>            oFileStream.Close()
>>
>>        Catch oError As Exception
>>
>>            Dim sErrorString As String
>>            sErrorString = "Message ---" & oError.Message
>>            sErrorString = sErrorString & vbCrLf
>>            sErrorString = sErrorString & "HelpLink ---" & oError.HelpLink
>>            sErrorString = sErrorString & vbCrLf
>>            sErrorString = sErrorString & "Source ---" & oError.Source
>>            sErrorString = sErrorString & vbCrLf
>>            sErrorString = sErrorString & "StackTrace ---" & oError.StackTrace
>>            sErrorString = sErrorString & vbCrLf
>>            sErrorString = sErrorString & "TargetSite ---" & oError.TargetSite.ToString
>>            MessageBox.Show(sErrorString, "Error")
>>
>>            End
>>
>>        End Try
>>
>>    End Function
>>
>>End Class
>>
>
>I think you want to change the line
oSoapFormatter.Serialize(oFileStream, oSoapFormatter)
to
oSoapFormatter.Serialize(oFileStream, oObjectToSave)
Also, note in the remarks section at http://msdn.microsoft.com/en-us/library/system.runtime.serialization.formatters.soap.soapformatter%28v=vs.110%29.aspx that SoapFormatter is obsolete and it is suggested that you use BinaryFormatter instead.
Previous
Reply
Map
View

Click here to load this message in the networking platform