Hi,
I am working with the beta version of the new .net framework (Whidbey) and I
encountered a problem with serialization that did'nt exist in the .net 2003
the situation is like this :
I have a class that inherits from dataset, and I want to serialize it , so I
created a serialization constructor that forwards the call to the base class
(the dataset) serialization constructor, normally, for this action to
succeed I am supposed to put an attribute on the super class (in this case
the dataset) that looks like that :
[XmlInclude (typeOf (<myClass>))]
so that the serializer will be able to deserialize my class where a dataset
was daclared, the problem is, that I can't put this attribute on the
dataset.
currrently the serializer is able to serialize my class but when it
desirializes it I get a dataset object and I can't cast it to the derived
class (casting fails),
so I need an alternative way to let the serializer know about the derived
class, so if anyone knows a way to do this without using the attribute I
would appreciate his help.
code sample that demonstrates the situation:
// the derived class
[Serializeable]
public class MyDataSet : DataSet
{
public MyDataSet() : base()
{
}
// serialization constructor
public MyDataSet(Seria lization info,StreamingC ontext context) :
base(info,conte xt)
{
}
}
// serializing the class
......
.......
MyDataSet ds = new MyDataSet();
XmlSerializer ser = new XmlSerializer(t ypeof(DataSet)) ;
StringWriter writer = new StringWriter();
ser.Serialize(w riter, ds);
........
........
// desirializing the class
MyDataSet newDs = new MyDataSet();
StreamReader reader = new StreamReader("S er.Xml", Encoding.UTF8);
newDs = ser.Deserialize (reader) as MyDataSet; // at this point the casting
fails and returns null.
.......
.......
thanks , ofer. 2 2357
Hi,
I can only point you the solution, but i'm not sure how it works...
Try to override ISerializable.G etObjectData(.. .), and don't forget
to call ((ISerializable ) base).GetObject Data(...).
Maybe you should try other serializer (e.g. binary or SOAP) for
test reason?
Regards
Marcin Hi,
I am working with the beta version of the new .net framework (Whidbey) and I encountered a problem with serialization that did'nt exist in the .net 2003 the situation is like this : I have a class that inherits from dataset, and I want to serialize it , so I created a serialization constructor that forwards the call to the base class (the dataset) serialization constructor, normally, for this action to succeed I am supposed to put an attribute on the super class (in this case the dataset) that looks like that : [XmlInclude (typeOf (<myClass>))]
so that the serializer will be able to deserialize my class where a dataset was daclared, the problem is, that I can't put this attribute on the dataset. currrently the serializer is able to serialize my class but when it desirializes it I get a dataset object and I can't cast it to the derived class (casting fails), so I need an alternative way to let the serializer know about the derived class, so if anyone knows a way to do this without using the attribute I would appreciate his help.
code sample that demonstrates the situation:
// the derived class
[Serializeable] public class MyDataSet : DataSet { public MyDataSet() : base() { }
// serialization constructor public MyDataSet(Seria lization info,StreamingC ontext context) : base(info,conte xt) { } }
// serializing the class ..... ...... MyDataSet ds = new MyDataSet();
XmlSerializer ser = new XmlSerializer(t ypeof(DataSet)) ;
StringWriter writer = new StringWriter();
ser.Serialize(w riter, ds);
.......
.......
// desirializing the class
MyDataSet newDs = new MyDataSet();
StreamReader reader = new StreamReader("S er.Xml", Encoding.UTF8);
newDs = ser.Deserialize (reader) as MyDataSet; // at this point the casting fails and returns null.
......
...... thanks , ofer.
ofer,
You are confusing the two different methods of serialization.
XmlSerializatio n does not use the Serializable attribute, or the custom
serialization constructor. This is for serialization using formatters that
implement the IFormatter interface.
If you need your class serialized into XML, assuming you don't have any
state beyond what is stored on the DataSet level, why not just call WriteXml
to get XML? Also, you might want to check out the BinaryFormatter or the
SoapFormatter.
Must your dataset be serialized into XML? If so, must that XML be
readable, or can it be incredibly complex?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"ofer" <pe******@bguma il.bgu.ac.il> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. .. Hi,
I am working with the beta version of the new .net framework (Whidbey) and I encountered a problem with serialization that did'nt exist in the .net 2003 the situation is like this : I have a class that inherits from dataset, and I want to serialize it , so I created a serialization constructor that forwards the call to the base class (the dataset) serialization constructor, normally, for this action to succeed I am supposed to put an attribute on the super class (in this case the dataset) that looks like that : [XmlInclude (typeOf (<myClass>))]
so that the serializer will be able to deserialize my class where a dataset was daclared, the problem is, that I can't put this attribute on the dataset. currrently the serializer is able to serialize my class but when it desirializes it I get a dataset object and I can't cast it to the derived class (casting fails), so I need an alternative way to let the serializer know about the derived class, so if anyone knows a way to do this without using the attribute I would appreciate his help.
code sample that demonstrates the situation:
// the derived class
[Serializeable] public class MyDataSet : DataSet { public MyDataSet() : base() { }
// serialization constructor public MyDataSet(Seria lization info,StreamingC ontext context) : base(info,conte xt) { } }
// serializing the class ..... ...... MyDataSet ds = new MyDataSet();
XmlSerializer ser = new XmlSerializer(t ypeof(DataSet)) ;
StringWriter writer = new StringWriter();
ser.Serialize(w riter, ds);
.......
.......
// desirializing the class
MyDataSet newDs = new MyDataSet();
StreamReader reader = new StreamReader("S er.Xml", Encoding.UTF8);
newDs = ser.Deserialize (reader) as MyDataSet; // at this point the casting fails and returns null.
......
...... thanks , ofer.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: ofer |
last post by:
Hi,
I am working with the beta version of the new .net framework (Whidbey) and I
encountered a problem with serialization that did'nt exist in the .net 2003
the situation is like this :
I have a class that inherits from dataset, and I want to serialize it , so I
created a serialization constructor that forwards the call to the base class
(the dataset) serialization constructor, normally, for this action to
succeed I am supposed to put...
|
by: okinrus |
last post by:
Can someone take a look at this code and figure out why
Serializable_base::add_serializer throws std::bad_alloc. The problem
seems to be the compiler because msvc++ 7.1 says
c:\LibSerial\LibSerial.cpp(83) : warning C4584: 'serial::E' :
base-class 'serial::A' is already a base-class of 'serial::C'
c:\LibSerial\LibSerial.cpp(10) : see declaration of
'serial::A'
c:\LibSerial\LibSerial.cpp(48) : see declaration of
'serial::C'
|
by: hs |
last post by:
Hi
I am serializing a dataset using a binary formatter as follows:
IFormatter formater = new BinaryFormatter();
formatter.Serialize(stream, ds); // ds=DataSet, stream=MemoryStream
....
DataSet ds2 = (DataSet)formatter2.Deserialize(stream2);
For the size of my DataSet, its taking 0.8 seconds to serialize and 2.3
seconds to deserialize.
|
by: Aaron Clamage |
last post by:
Hi,
I'm not sure that if this is the right forum, but any help would be greatly
appreciated.
I am porting some java serialization code to c# and I can't figure out the
correct way to do it. It seems that either I can use default serialization
or implement ISerializable. Is there any way to do both (e.g. extend the
default serialization). In other words, I want to be able to implement my
custom serialization code but call the...
|
by: Janne |
last post by:
I have a problem with Xml and Serialization.
I use serialization to get Xml as a result. All
Serialization examples in Microsoft documentation writes
the result to a file.
I don't want a file, I want an XML-object (XmlNode)
instead that I can pass as a parameter to another method.
How can I do that?
| |
by: Aaron Clamage |
last post by:
Hi,
Could someone please confirm the following?
I think I have found a subtle .NET serialization bug. It occurs when object
has a list of items containing another object of the same type and both
objects have a non-static member reference to some other static object. In
this case, I get an InvalidArgument exception when I try to access the
non-static member of the child class. I've included a code sample to
clarify. This "bug" is...
|
by: tony lock |
last post by:
I have a class inherited from Control, which I want to serialize, since
Control is not Serializable, I have had to implement ISerializable. This
works but I now want to inherit this base class into a number of other
classes, I was assuming that I could just mark them as and use
automatic serialization but this does not work (The new class cannot
deserialize, because it does not have the correct constructor ie one with
arguments...
|
by: Joe |
last post by:
I've tracked the performance issue down to a single class. This class
derives from CollectionBase and stores a basic value type such as string,
int, double, etc... I also store the type itself which you can see I'm using
when calling AddValue.
I implemented ISerializable and GeteObjectData.
Here's what I tried:
for (int i = 0; i < this.Count; i++)
info.AddValue("item" + i.ToString(), this, typeof(type) );
|
by: Paez |
last post by:
Hi There.
This post is a extension of thread "Serialize or not to Serialize", on 5 of
December of 2006.
The reason why my teacher insists that a WS cannot return a Dataset is due
to low rate networks, not due to SOAP schemas. I think that's because a XML
Dataset is too large.
So, in my WS, I want to turn my dataset in some type of class, and then send
|
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...
|
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...
| |
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...
|
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,...
|
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...
|
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();...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |