473,714 Members | 3,077 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Collecti ons
Imports System.Runtime. Serialization.F ormatters.Soap
'************** *************** *************** *************
Public Class Form1
'************** *************** *************** ************
Inherits System.Windows. Forms.Form
Public SGWArt As New classArt

#Region " Windows Form Designer generated code "

+ Private Sub Form1_Load(ByVa l sender As System.Object,
_
ByVal e As System.EventArg s) Handles MyBase.Load .

Private Sub Form1_Closing(B yVal sender As Object, _
ByVal e As
System.Componen tModel.CancelEv entArgs) _
Handles MyBase.Closing
SGWArt.SaveArt( Form2Art)
SGWArt.displayA rtList() 'added to assist debug!
SGWArt.SaveFile ()
SGWArt = Nothing
Beep()
End Sub

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

+ Private Sub BtnDel_Click(By Val sender As
System.Object, _
ByVal e As System.EventArg s) 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.EventArg s) Handles
BtnFirst.Click.

+ Private Sub BtnLast_Click(B yVal sender As Object, _
ByVal e As System.EventArg s) Handles
BtnLast.Click.

+ Private Sub BtnPrevious_Cli ck(ByVal sender As Object,
_
ByVal e As System.EventArg s) Handles
BtnPrevious.Cli ck.

Private Sub BtnNext_Click(B yVal sender As Object, _
ByVal e As System.EventArg s) 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.T ext) 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.GetThum bnailImage(MyWi dth,
MyHeight, _
Nothing, New IntPtr)
pbPict.Image = MyImage
Else
pbPict.Image = Nothing
End If
End Sub

Private Sub pbPict_DoubleCl ick(ByVal sender As
Object, _
ByVal e As System.EventArg s) Handles
pbPict.DoubleCl ick
If jpgDialog.ShowD ialog = DialogResult.OK Then
'pbPict.Text = jpgDialog.FileN ame
tbDesc.Text = jpgDialog.FileN ame
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(ArtF ileName,
FileMode.Create )
Try
sf.Serialize(fs , ArtList)
Catch ex As Exception
MsgBox(Msg1 & ex.Message,
MsgBoxStyle.Cri tical, 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(ArtFileN ame) Then
Dim fs As New FileStream(ArtF ileName,
FileMode.Open)
Dim sf As New SoapFormatter
Try
ArtList = CType(sf.Deseri alize(fs),
ArrayList)
'ArtList = DirectCast(sf.D eserialize(fs),
ArrayList)
Catch ex As Exception
MsgBox(Msg1 & ex.Message,
MsgBoxStyle.Cri tical, 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(Ar tIndex)
End Function

Public Sub SaveArt(ByVal MyArt As objArt)
'put MyArt into ArtList at current index
ArtList.Item(Ar tIndex) = 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 1102

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

Similar topics

2
4728
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 Xml key. and refers to the Xml key: <a1:C_XOptions id="ref-1" xmlns:a1="http://schemas.microsoft.com/clr/nsassem/SU2000Plus/sekretariat_RM
0
2084
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 defaults as appropriate. I'm trying to do them both using the SoapFormatter to serialize. But when I try to read in the user's prefs after reading the defaults, both from similar Soap files, I get this exception: ----...
2
6289
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 limitation (i.e. public members). SoapFormatter is better to serialize arbitrary data. I have done some tests and SoapFormatter is faster 5 times than XmlSerializer. I don't undestand it, I have tried large arrays, small string .... the result seems the...
2
2163
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, GetObjectData and a constructor that takes two arguments (a SerializationInfo object and a StreamingContext object). It appears with the release of .net 2.0 that support for the SoapFormatter is 'frozen' and that the direction we should take is...
1
2687
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 SoapFormatter. The following program gets the exception: "The data at the root level is invalid. Line 55, position -460." This code works fine if I use a BinaryFormatter instead of a SoapFormatter. Any ideas? Here is a test program:
2
3770
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 implemented using Inherits System.Collections.Specialized.NameObjectCollectionBase and also has the <Serializable()> flag before the class name declaration. In the calling code, I'm successfully serializing the object to an XML file using a...
0
1624
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 just goes to the end of the file. After reading the first object, the fStream.Position is pointed to the end of the file. The collection serializes/deserilizes fine when I just serialize the hashtable vs. each object in the hashtable. Does...
0
796
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 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...
5
2613
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 ASP.Net 2.0 using VB.Net and had developed an application that ran correctly on my development server but would not run on the shared hosting paltform which I use. The shared hosting runs in medium trust and produced the error "That assembly does not...
0
9179
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9077
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9023
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7954
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6638
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5959
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4729
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3160
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2525
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.