473,566 Members | 2,784 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Deserializing into a pre-exisiting object

What happens to an object which is not nothing has another object
deserialized into it? I assume that the data in it is completely destroyed by
the new object.

I am interested because I have some strange persisting data elements
cropping up whose origins I am attempting to identify. I was wondering if
deserializing in the manner described above might be responsible if the
original object is not actually destroyed.
Nov 21 '05 #1
4 1067
Andrew,

I do understand almost nothing from your message. However an object that has
a reference to or from another existing object will never be released.

I hope this helps,

Cor
Nov 21 '05 #2
"Andrew E Chapman" <An************ @discussions.mi crosoft.com> wrote in
message news:9D******** *************** ***********@mic rosoft.com...
What happens to an object which is not nothing has another object
deserialized into it?


How would you achieve this, anyway? I've always deserialised my
objects using a Constructor for the class, so the object /can't/ exist
already.

Public Sub New( _
ByVal info As System.Runtime. Serialization.S erializationInf o _
, ByVal context As System.Runtime. Serialization.S treamingContext _
)

Regards,
Phill W.
Nov 21 '05 #3
Apologies for my opacity. The code below illustrates what I mean. AThing is
declared and the constructor is not called. The object is created with the
first call to the Deserialize sub, but what happens to it with the second? I
had thought that it would be recreated and that the first deserialized AThing
would be replaced by the second. Is this what occurs?

Dim AThing As Thing
....

'1
DeserializeThin g(FileNameA, AThing)

'Do some stuff to AThing

'2
DeserializeThin g(FileNameB, AThing)

'Is AThing completely reconstituted by call 2?
....
sub DeserializeThin g(byval fileName as string, byval T as Thing)
Dim fs As FileStream = New FileStream(file Name, FileMode.Open)
Dim bf As New BinaryFormatter
bf.AssemblyForm at = Formatters.Form atterAssemblySt yle.Simple
T = DirectCast(bf.D eserialize(fs), Thing)
fs.Close()
end sub
Nov 21 '05 #4
"Andrew E Chapman" <An************ @discussions.mi crosoft.com> wrote in
message news:DE******** *************** ***********@mic rosoft.com...
sub DeserializeThin g(byval fileName as string, byval T as Thing)
T = DirectCast(bf.D eserialize(fs), Thing)
end sub DeserializeThin g(FileNameB, AThing)
' Is AThing completely reconstituted ... ?


It certainly should /not/ be, because AThing is passed ByVal to the
method and yes; I realise it's an reference type.

The deserialisation creates a new instance of a Thing object, and
this is assigned to the /local/ variable T, i.e. a "pointer" to the new
object is stored in T. Because you're only passing the "pointer" to
AThing by value, you're method /can't/ assign a value to it, i.e. you
can't "throw away" the current instance in AThing and replace it with
a new one, which is what you're trying to do, and why your object
"seems" to be retaining it's previous values - it is!!

Pass your Thing (ooh, err, missus) into the method ByRef, and you'll
be able to "return" the new, deserialised instance of the object "into"
AThing.
Better still, make this method into a function and return the new
object explicitly, as in

Function DeserializeThin g(byval fileName as string) as Thing
T = DirectCast(bf.D eserialize(fs), Thing)
Return T
End Function
.. . .
AThing = DeserializeThin g( "file" )

HTH,
Phill W.
Nov 21 '05 #5

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

Similar topics

0
1053
by: Jon Fairchild | last post by:
I am getting the following error when deserializing an XML with attribute overrides: "There is an error in XML document (2, 2) … <RulesConfig xmlns=''> was not expected" My XML looks like this: <RulesConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"...
0
1427
by: Peter Theill | last post by:
Hi, I'm having an issue with deserializing some xml using a proxy class generated by "xsd.exe". My proxy class contains this class definition: public class IqProfileType {
0
916
by: Amit | last post by:
Hi Friends, I am stuck in a situation that i need help for.The situation is like i have an xml coming from the database in the format <BASE> <Base> <UserName>A</UserName> <Pasword>1233</Password> <Profile> <Name>User</Name>
2
3088
by: Earl Teigrob | last post by:
I am saving and restoring value types such as Int32, DateTime and Boolean in strings. I was wondering if there is a mechanism build into .NET for serializing and deserializing these to string format. I can, of course, serialize a class to a file, either binary or XML, but this is not what I am looking for. Currently I am using ToString() or...
1
1438
by: Bob Rock | last post by:
Hello, always having to validate an XML stream against a XSD may add up an important overhead. My XMLs are usually the result of serializing a class instance and often in my applications what I end up doing is just deserializing it back into a new instance of the same class. Considering what I just said what I often end up doing is not...
6
1579
by: Steve Teeples | last post by:
I use serialization to write class data to a file. During my development of this class I need to add properties or fields on occation. After adding a property, when deserializing the data saved to disk I get an exception error indicating that the class data members no longer match. To avoid the exception errors, how can I retrieve data...
1
1312
by: Kevin R | last post by:
Hi All, I have a binary file, the first few k of which contains some information which I need to stick in to an array of types,let's call them Wongas. Each Wonga is made up of two ulongs and a 24 byte character array. I need to read in an array of Wongas from the binary file and I need to specify how many to read in, as the file is only...
7
16050
by: farseer | last post by:
Hi, i am getting an error when trying to deserialize and xml. the error is shown below. i get this error regardless if i try to desearialize in C# or VB. the XML itself does infact contain a top level "PDocument" note which contains an xmlns namespace and some other attriute. is the error belowing telling it doesn't like that namespace...
0
7786
by: Sivajee Akula | last post by:
Hello All, I am trying to consume a .NET Service from Adobe LiveCycle Workflow. The service deals with complex objects. I am getting the following exception at the time of invocation of the service, and due to which my workflow gets stalled. When I searched the net, I found many posts reporting this error, but none with a solution. There is...
0
974
by: ullner | last post by:
I have an XML fil that looks like this: <Environment> <AreaOfInterest> <Name>ScenarioMap</Name> <UpperRight> <GDC> <Latitude>-179</Latitude> <Longitude>-179</Longitude>
0
7666
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...
0
7584
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...
0
7888
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. ...
0
8108
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...
1
7644
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...
0
6260
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...
1
5484
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...
0
5213
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...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.