473,671 Members | 2,283 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML Deserialization

Is there a way to be notified when the deserialization of an XML is
complete, like a callback method?

I tried the IDeserializatio nCallback interface, but that doesnt for
XML-Deserialization .

thanks
josh

Dec 15 '05 #1
12 7760
Use a synchronous overload of the XmlSerializer.D eserialize method; when it
returns, it is finished.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

"yoshijg" <jo*****@gmail. com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
Is there a way to be notified when the deserialization of an XML is
complete, like a callback method?

I tried the IDeserializatio nCallback interface, but that doesnt for
XML-Deserialization .

thanks
josh

Dec 15 '05 #2
Hi Kev,

Do you mean something like this...

--
FooType fooobj;
XmlSerializer xmlObj = new System.Xml.XmlS erialialzer(Typ eOf(FooType));
Filestream strObj = new Filestream("foo ", Open);
fooobj = xmlObj.Deserial ize( strObj );
fooObj.Deserial izeComplete(); //Notify manually
--

Yeah, i am doing that now... but I want the object being created inside
of the "Deserializ e" method to be notified when it's done being created
by the "XmlSerializer" .

I can do what you suggest and it's easy...but some coder may forget to
call "DeserializeCom plete". Now I can wrap this whole thing in a
function call, but that's just another hoop everybody doesnt need to
jump through.

Now why doesn't implementing IDeserializatio nCallback work?

Dec 15 '05 #3
I don't know why. How are you implementing it?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

"yoshijg" <jo*****@gmail. com> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.com.. .
Hi Kev,

Do you mean something like this...

--
FooType fooobj;
XmlSerializer xmlObj = new System.Xml.XmlS erialialzer(Typ eOf(FooType));
Filestream strObj = new Filestream("foo ", Open);
fooobj = xmlObj.Deserial ize( strObj );
fooObj.Deserial izeComplete(); //Notify manually
--

Yeah, i am doing that now... but I want the object being created inside
of the "Deserializ e" method to be notified when it's done being created
by the "XmlSerializer" .

I can do what you suggest and it's easy...but some coder may forget to
call "DeserializeCom plete". Now I can wrap this whole thing in a
function call, but that's just another hoop everybody doesnt need to
jump through.

Now why doesn't implementing IDeserializatio nCallback work?

Dec 16 '05 #4
Hey kev,

Taking from the example above...

The only thing to add/note is that FooType implements the
IDeserializatio nCallback , and the call to deserialize looks like

FooType fooobj;
XmlSerializer xmlObj = new System.Xml.XmlS erialialzer(Typ eOf(FooType));
Filestream strObj = new Filestream("foo ", Open);
fooobj = xmlObj.Deserial ize( strObj );
---------------

Note, I am not calling OnDeserializati on manually like above.

Dec 16 '05 #5
What I meant was, how are you implementing IDeserializatio nCallback? The
code you just posted doesn't do this. Your question was "why doesn't it
work?" In order to see why it doesn't work, I have to see how you're using
it.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

"yoshijg" <jo*****@gmail. com> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.com.. .
Hey kev,

Taking from the example above...

The only thing to add/note is that FooType implements the
IDeserializatio nCallback , and the call to deserialize looks like

FooType fooobj;
XmlSerializer xmlObj = new System.Xml.XmlS erialialzer(Typ eOf(FooType));
Filestream strObj = new Filestream("foo ", Open);
fooobj = xmlObj.Deserial ize( strObj );
---------------

Note, I am not calling OnDeserializati on manually like above.

Dec 16 '05 #6
/*
Serializes/Deserializes properly as expected. But doesnt call the
OnDeserializati on();
*/

using System;
using System.Xml.Seri alization;
using System.IO;
using System.Runtime. Serialization;

namespace Test
{
public class Class1
{
[STAThread]
static void Main(string[] args)
{
//Serialize to disk first
Foobar fooObj = new Foobar();
XmlSerializer xml = new XmlSerializer(t ypeof(Foobar));
StreamWriter ios = new StreamWriter("f oobar.xml");
xml.Serialize(i os, fooObj);
ios.Close();

//Deserialize from disk
Foobar fooObj2 = null;
XmlSerializer xml2 = new XmlSerializer(t ypeof(Foobar));
FileStream ios2 = new FileStream("foo bar.xml",
FileMode.Open);
fooObj2 = (Foobar)xml.Des erialize(ios2);
ios2.Close();

}
}

[Serializable()]
public class Foobar
: IDeserializatio nCallback
{
private string m_Foo = "fooooo";

public string FooProperty
{
get
{
return m_Foo;
}
set
{
m_Foo = value;
}
}

public void OnDeserializati on(Object sender)
{
Console.WriteLi ne("Deserializa tion complete");
}
}
}

Dec 17 '05 #7
/*
Serializes/Deserializes properly as expected. But doesnt call the
OnDeserializati on();
*/

using System;
using System.Xml.Seri alization;
using System.IO;
using System.Runtime. Serialization;

namespace Test
{
public class Class1
{
[STAThread]
static void Main(string[] args)
{
//Serialize to disk first
Foobar fooObj = new Foobar();
XmlSerializer xml = new XmlSerializer(t ypeof(Foobar));
StreamWriter ios = new StreamWriter("f oobar.xml");
xml.Serialize(i os, fooObj);
ios.Close();

//Deserialize from disk
Foobar fooObj2 = null;
XmlSerializer xml2 = new XmlSerializer(t ypeof(Foobar));
FileStream ios2 = new FileStream("foo bar.xml",
FileMode.Open);
fooObj2 = (Foobar)xml.Des erialize(ios2);
ios2.Close();

}
}

[Serializable()]
public class Foobar
: IDeserializatio nCallback
{
private string m_Foo = "fooooo";

public string FooProperty
{
get
{
return m_Foo;
}
set
{
m_Foo = value;
}
}

public void OnDeserializati on(Object sender)
{
Console.WriteLi ne("Deserializa tion complete");
}
}
}

Dec 17 '05 #8
Well, you havent implemented the interface. See the following MSDN article:

http://msdn.microsoft.com/library/de...ationTopic.asp

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

"yoshijg" <jo*****@gmail. com> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.com.. .
/*
Serializes/Deserializes properly as expected. But doesnt call the
OnDeserializati on();
*/

using System;
using System.Xml.Seri alization;
using System.IO;
using System.Runtime. Serialization;

namespace Test
{
public class Class1
{
[STAThread]
static void Main(string[] args)
{
//Serialize to disk first
Foobar fooObj = new Foobar();
XmlSerializer xml = new XmlSerializer(t ypeof(Foobar));
StreamWriter ios = new StreamWriter("f oobar.xml");
xml.Serialize(i os, fooObj);
ios.Close();

//Deserialize from disk
Foobar fooObj2 = null;
XmlSerializer xml2 = new XmlSerializer(t ypeof(Foobar));
FileStream ios2 = new FileStream("foo bar.xml",
FileMode.Open);
fooObj2 = (Foobar)xml.Des erialize(ios2);
ios2.Close();

}
}

[Serializable()]
public class Foobar
: IDeserializatio nCallback
{
private string m_Foo = "fooooo";

public string FooProperty
{
get
{
return m_Foo;
}
set
{
m_Foo = value;
}
}

public void OnDeserializati on(Object sender)
{
Console.WriteLi ne("Deserializa tion complete");
}
}
}

Dec 17 '05 #9
Hey Kev,

Thanks for the article. I guess IDeserializatio nCallback only works
with the "BinaryFormatte r", which really seems counter intuitive.
Don't you? Wouldn't you expect a Callback to occur for any type of
Deserialization .
josh

Dec 18 '05 #10

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

Similar topics

2
2357
by: Serg | last post by:
Hi. I have a problem with deserialization decimal value. I have a simple class: public class A { public decimal d; } The serialization a value 0.00000001 is OK. The file is
3
1652
by: TEK | last post by:
There seems to be a bug when deserialization some classes in the .NET framework. If you try to deserialize a class that has a base class that holds a struct with a member that is implementing the ICollection interface, this causes the deserialization to fail. In my case this is a huge problem, and any suggestion for a workaround would be happily received. A small example of a set of classes that reproduces the problem is included
2
3822
by: Snowman | last post by:
Suppose I have a RootObject which holds a collection of other objects. The other objects have a property (Parent) which refers back to the "parent" collection (b.t.w. my collection is based on CollectionBase), in similar fashion as the object models of MS Office. I want to serialize this object graph (with RootObject as the xml document element) without Parent property serialized, this may be done by adding XmlIgnoreAttribute on the...
3
9792
by: Amadelle | last post by:
Hi all and thanks in advance for your help, I am having problems deserializing an object which seems to be serializing just fine. I save the byte array of the serialized object in the database (when I check the database the field that holds the binary data seems populated), but when I want to deserialize this same byte array the application fails and gives me the following error: Binary stream does not contain a valid BinaryHeader, 0...
3
2063
by: AnkitAsDeveloper [Ankit] | last post by:
Hi i am serializing a 'ref struct' object as follows : private: void Seri( String ^path, Object^ obj ) { FileStream^ fileStrm ; try { //Serialize entire object into Binary stream
3
9791
by: parrot toes | last post by:
Summary: I have been trying to make requests of a web service provided by Axis using a dotnet client with code generated by wsdl.exe and have been getting exceptions when trying to process the response. As a result of seraching news groups I guessed that the SOAP response defines an array element in a way that causes the dotnet deserialization routines to put the content in a generic object array (object) BUT the content is supposed to...
1
3738
by: parrot toes | last post by:
I tried to post this question before, but there was an error when posting. I case it did get posted and in order to avoid duplication, I'll just repost a summary. I have written a dotnet client that accesses a Axis provided web service. The client uses the code generated, using wsdl.exe, from the wsdl file provided by the web service provider. The web response has the following schema (roughly):
8
3460
by: ashoksrini | last post by:
Hi All, I have the below requirement and would like to get some feeback from the group on the best way to implement: 1. I have WSDL defined exposing few web services. 2. We dont have a requirement to have a server web service class. (reasons below) 3. I want to develop something like this - when client makes a web service call, on the server I can intercept the SOAP message (XML doc itself),
5
2290
by: Greg Allen | last post by:
I am consuming a web service and using the generated Reference.cs to access the service and the objects associated with it. I have run into a problem where some inherited classes are not being deserialized. I have verified that the XML being returned by the service contains the tags I am expecting, but they don't show up in the resulting object. Here's the relevant portion of the Reference.cs file: public class FormSection {
7
16153
by: Andrew | last post by:
Hi, I am using DataContractJsonSerializer to deserialize JSON string in C# objects but I am having a problem. Suppose I have a class: class Item { public ItemId Id { get; set; }
0
8912
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...
1
8597
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
8669
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
7428
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...
0
4222
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4403
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2809
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
2049
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1807
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.