473,388 Members | 1,557 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

SoapFormatter Help

I have an error that I have not been able to find. Any
insight you can offer would be most appreciated. I
believe that the problem is associated with the
SoapFormatter.

The application allows the user to document a collection
of art objects. Each object is stored in an arrayList as
an objArt. To simplify finding my problem, I have
eliminated all the code except the code for six buttons,
the Title and Description textboxes and the Photograph
picturebox. The buttons allow the user to display the
first (|<),previous (<),next (>) and last (>|) objects in
the arrayList. The two additional buttons add (+) a new
object and delete (X) the current object. The buttons
are working fine. As the user navigates to a different
record any changes to the textboxes is saved to the
arrayList. When the application is closed the arrayList
is serialized with the SoapFormatter and written to a
file. I have included an open file dialog which is
accessed by double clicking on the picturebox. The JEPG
filename is displayed in the Description textbox and the
image is sized and displayed in the picturebox.

My problem is: If I use the open file dialog to change
the Description textbox the changes to the arrayList are
NOT saved when the application closes. If I manually
edit the Description textbox the changes are saved to the
file when the application closes. I have stepped through
the code when the application closes and I have observed
that in either case the changes have been made to the
arrayList and the SaveFile routine is called.

Here is the code with the nonessential routines minimized:

Imports System.IO
Imports System.Collections
Imports System.Runtime.Serialization.Formatters.Soap
'************************************************* ********
Public Class Form1
'************************************************* *******
Inherits System.Windows.Forms.Form
Public SGWArt As New classArt

#Region " Windows Form Designer generated code "

+ Private Sub Form1_Load(ByVal sender As System.Object,
_
ByVal e As System.EventArgs) Handles MyBase.Load .

Private Sub Form1_Closing(ByVal sender As Object, _
ByVal e As
System.ComponentModel.CancelEventArgs) _
Handles MyBase.Closing
SGWArt.SaveArt(Form2Art)
SGWArt.displayArtList() 'added to assist debug!
SGWArt.SaveFile()
SGWArt = Nothing
Beep()
End Sub

Private Sub BtnAdd_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles
BtnAdd.Click
SGWArt.AddArt()
SGWArt.SetIndx(SGWArt.ArtCount - 1)
Art2Form(SGWArt.GetArt())
StatusUpdate()
End Sub

+ Private Sub BtnDel_Click(ByVal sender As
System.Object, _
ByVal e As System.EventArgs) Handles
BtnDel.Click.

+ Sub StatusUpdate().

Sub Art2Form(ByVal MyArt As objArt)
With MyArt
tbTitle.Text = .Title
tbDesc.Text = .Des
pbPict.Text = .Pic
End With
DisplayJPG()
End Sub

Function Form2Art() As objArt
Dim MyArt As New objArt
With MyArt
.Title = tbTitle.Text
.Des = tbDesc.Text
.Pic = pbPict.Text
End With
Form2Art = MyArt
MyArt = Nothing
End Function

+ Private Sub BtnFirst_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles
BtnFirst.Click.

+ Private Sub BtnLast_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles
BtnLast.Click.

+ Private Sub BtnPrevious_Click(ByVal sender As Object,
_
ByVal e As System.EventArgs) Handles
BtnPrevious.Click.

Private Sub BtnNext_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles
BtnNext.Click
SGWArt.SaveArt(Form2Art)
If SGWArt.GetIndx < SGWArt.ArtCount - 1 Then
SGWArt.SetIndx(SGWArt.GetIndx + 1)
Art2Form(SGWArt.GetArt)
StatusUpdate()
End If
End Sub

Sub DisplayJPG()
Dim MyImage As Image
Dim MyWidth As Integer
Dim MyHeight As Integer
Dim pbArtSize As Integer
If System.IO.File.Exists(tbDesc.Text) Then
MyImage = Image.FromFile(tbDesc.Text)
pbArtSize = pbPict.Width 'Note pbArt must be
square
MyWidth = MyImage.Width
MyHeight = MyImage.Height
'Set the width & height of the thumbnail
If MyWidth > MyHeight Then
MyHeight = pbArtSize * MyHeight / MyWidth
MyWidth = pbArtSize
Else
MyWidth = pbArtSize * MyWidth / MyHeight
MyHeight = pbArtSize
End If
MyImage = MyImage.GetThumbnailImage(MyWidth,
MyHeight, _
Nothing, New IntPtr)
pbPict.Image = MyImage
Else
pbPict.Image = Nothing
End If
End Sub

Private Sub pbPict_DoubleClick(ByVal sender As
Object, _
ByVal e As System.EventArgs) Handles
pbPict.DoubleClick
If jpgDialog.ShowDialog = DialogResult.OK Then
'pbPict.Text = jpgDialog.FileName
tbDesc.Text = jpgDialog.FileName
DisplayJPG()
End If
End Sub

+ Sub MyToolTips().

End Class

'************************************************* ********
***
<[Serializable]()> Public Class
objArt '******
'************************************************* ****
***
Public Title As String
Public Des As String
Public Pic As String
End Class

'************************************************* ********
***
Public Class
classArt '******
'************************************************* ****
***
Private Shared ArtList As New ArrayList 'shared added
1/5/05
Private ArtIndex As Integer
Private ArtFileName As String = "art.xml"

Public Sub SaveFile() 'save ArtList to ArtFile
Dim Msg1 As String = "ArtFile was not saved!
Reason: "
Dim Msg2 As String = "Art"
Dim sf As New SoapFormatter
Dim fs As New FileStream(ArtFileName,
FileMode.Create)
Try
sf.Serialize(fs, ArtList)
Catch ex As Exception
MsgBox(Msg1 & ex.Message,
MsgBoxStyle.Critical, Msg2)
Finally
fs.Close()
End Try
End Sub

Public Sub GetFile() 'get ArtList from ArtFile
Dim Msg1 As String = "Failed to open ArtList!
Reason: "
Dim Msg2 As String = "Art"
If System.IO.File.Exists(ArtFileName) Then
Dim fs As New FileStream(ArtFileName,
FileMode.Open)
Dim sf As New SoapFormatter
Try
ArtList = CType(sf.Deserialize(fs),
ArrayList)
'ArtList = DirectCast(sf.Deserialize(fs),
ArrayList)
Catch ex As Exception
MsgBox(Msg1 & ex.Message,
MsgBoxStyle.Critical, Msg2)
Finally
fs.Close()
sf = Nothing
fs = Nothing
End Try
Else
AddArt()
End If
End Sub

Public Function GetArt() As objArt
'return Art object from ArtList at current index
GetArt = ArtList.Item(ArtIndex)
End Function

Public Sub SaveArt(ByVal MyArt As objArt)
'put MyArt into ArtList at current index
ArtList.Item(ArtIndex) = MyArt
End Sub

+ Public Sub AddArt().

+ Public Function ArtCount() As Integer.

+ Public Sub DelArt().

+ Public Function SetIndx(ByVal Indx As Integer) As
Integer.

+ Public Function GetIndx() As Integer.

Public Function prtArtList()
Dim output As String
For Each myArt As objArt In ArtList
With myArt
output = .Title & " " & .Des
End With
Next
End Function

End Class

Nov 21 '05 #1
0 782

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Wiktor Zychla | last post by:
After signing all my assemblies with strong keys, I've found that the application refuses to deserialize any SOAP serialized data. The message says: Parse error, no assembly associated with the...
0
by: Philip Reed | last post by:
I'm trying to write a preferences-handling infrastructure that serializes prefs to XML. Basically I want to read in a common "default" prefs set, then read in the user's prefs and override the...
2
by: Jarda | last post by:
Hi all, i'm looking for some performance comparison some charts. I have read the xmlserializer is better, more flexible and faster (analyzing data types in constructor), but there are some...
2
by: Paul | last post by:
We currently persist our objects to xml/soap files using a SoapFormatter. We control the serialization and de-serialization by implementing the ISerializable and its two interface methods, namely,...
1
by: Jim S | last post by:
I have an application where I have to make a tree of objects. To do this, I have my own node class. At certain points in the application, I need to save data. I am having a problem with the...
2
by: Phillip Galey | last post by:
I have an object called Place which contains only string properties and has the <Serializable()> flag before the class name declaration. I also have a collection object called Places, which is...
0
by: JackRazz | last post by:
I'm trying to serialize a collection to a file stream by serializing each object individually. The code below works fine with the BinaryFormatter, but the SoapFormatter reads the first object and...
0
by: GrandpaB | last post by:
I have an error that I have not been able to find. Any insight you can offer would be most appreciated. I believe that the problem is associated with the SoapFormatter. The application allows...
1
by: Hotlips | last post by:
I'm trying to use an SoapFormatter with a generic List (List<int>) (.NET 2.0) When I use it I get an exception that states that the collections from Generic-namespace cannot be used with the...
5
by: =?Utf-8?B?TWFydHluIEZld3RyZWxs?= | last post by:
Hi there. I posted an earlier issue under the name "That assembly does not allow partially trusted callers" but have now identified what the issue is. As explained before I am working in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.