473,614 Members | 2,076 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 1095

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

Similar topics

2
4727
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
2076
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
6282
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
2161
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
2678
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
3756
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
1620
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
794
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
2606
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
8182
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8130
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8627
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8579
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...
0
7093
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
6088
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
4127
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2568
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
1
1747
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.