473,910 Members | 5,613 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 7775
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
2373
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
1670
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
3830
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
9804
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
2074
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
9800
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
3754
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
3479
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
2299
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
16172
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
10037
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
9879
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
11349
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
10921
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
10541
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
9727
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
7250
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
5939
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
6142
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.