473,780 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Deserialization bug, workaround or fix desperatly needed

TEK
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
at the end of the post.
I initially tought that the source of the problem was connected to my
collection having a intenal hashtable, however the same issue occure even if
none of the ICollection methods is actually implemented.

Code to test the issue:

FooA fooA = new FooA();
SerializationTe st(fooA);
private void SerializationTe st(object o){
FooA o = new FooA;
BinaryFormatter formatter = new BinaryFormatter ();
System.IO.Memor yStream memStream = new System.IO.Memor yStream();
try{
formatter.Seria lize(memStream, o);
memStream.Seek( 0, System.IO.SeekO rigin.Begin);
object clone = formatter.Deser ialize(memStrea m);
}finally{
memStream.Close ();
}
}


using System;
using System.Collecti ons;

namespace TestDeserializa tionIssue01
{
[Serializable]
public class FooA : FooAbstract {
public FooA(){}
}

[Serializable]
public abstract class FooAbstract
{
[Serializable]
private struct FooAbstractData {
public MyCollection myCollection;
public FooAbstractData (MyCollection collection){
myCollection = collection;
}
}
private FooAbstractData _data = new FooAbstractData (new MyCollection()) ;

public FooAbstract(){}
}

[Serializable]
public class MyCollection : ICollection {
//Hashtable _hash;
public MyCollection(){
/*_hash = new Hashtable();*/
}
public bool IsSynchronized {
get {return false;/*return _hash.IsSynchro nized;*/}
}
public int Count {
get {return 0;/*return _hash.Count;*/}
}
public void CopyTo(Array array, int index) {
/*_hash.Values.C opyTo(array, index);*/
}

public object SyncRoot {
get {return typeof(MyCollec tion);/*return _hash.SyncRoot; */}
}

public IEnumerator GetEnumerator() {
return null; /*return _hash.Values.Ge tEnumerator();*/
}
}
}
Jul 21 '05 #1
3 1662
TEK
Cleaner classes to reproduce the issue included below.
Serializing/deserialzing class FooAbstract works with no problem.
Serializing/deserializing class FooA does not work.

[Serializable]
public class FooA : FooAbstract {
public FooA(){}
}
[Serializable]
public class FooAbstract
{
[Serializable]
private struct FooAbstractData {
public ArrayList collection;
public FooAbstractData (ArrayList col){
collection = col;
}
}
private FooAbstractData _data;

public FooAbstract(){
_data = new FooAbstractData (new ArrayList());
}
}
Jul 21 '05 #2
TEK
Even more info.
The issue is actually not related to ICollection or any list at all.
If there is any class value included in the struct, the serialization will
fail for the inherited class.
If the value is a "native" type as string, int, Guid or a new struct, it
will work.

TEK
Jul 21 '05 #3
Try with XmlInclude(Syst em.Collection.. ....).
I have had recently a problem when serializing enums, i solved it by
changing the place where i declare the enum. Originally it was declared in
the class that used it. But the XmlSerializer did not work well with its
values, so I changed this configuration and put the enum in the top class of
the object model's

I apologise by my english
"TEK" <trond-eirik.at.kolloe n.no> escribió en el mensaje
news:e7******** ******@tk2msftn gp13.phx.gbl...
Even more info.
The issue is actually not related to ICollection or any list at all.
If there is any class value included in the struct, the serialization will
fail for the inherited class.
If the value is a "native" type as string, int, Guid or a new struct, it
will work.

TEK

Jul 21 '05 #4

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

Similar topics

0
1033
by: dave v | last post by:
I thought I read in an earlier post that there are known issues with deserialization in the System.Data.OracleClient.dll. Can anyone expand on that or give a workaround? I'm calling a custom database component that uses ODP.NET from a BizTalk 2004 map. When this component throws a System.Data.OracleClient.OracleException, I get this in the EventLog: Failed while creating a NUSTestHarness.NUSTest service.
1
2084
by: Tom L | last post by:
Simple deserialization help needed please... I have a packet of xml in a string, and need to get that into a reader./stream of some sort so I can properly use deserialize.. here's my deserialization routine (its part of a property as you can tell).. Set(ByVal Value As String) Dim serializer As New XmlSerializer(GetType(Package)) Dim xmlstream As New MemoryStream
2
9452
by: Shone | last post by:
I would like to perform a 2-pass XML reading from a stream. Once using the Validating reader, just to confirm the validity against the schema, and next time to do a reading to extract the data. Actually, second time I do a deserialization, the data from XML is fed directly to an object. The problem I am experiencing is the error at the second reading attempt, and error description implies that reader is winded to the end of the XML and...
3
9795
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...
3
260
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
5
2294
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 {
3
5000
by: John Glover | last post by:
To whoever can help, I've been having a problem with XML deserialization lately. I needed to serialize and deserialze two objects which inherited from Hashtable. Because IDictionary implementations cannot be serialized, I had to take matters into my own hands by implementing a wrapper over the Hashtable which implemted IXmlSerializable. I called it XmlHashtable. It has, among other convenience methods, a method
0
1315
by: =?Utf-8?B?UGllcmNlQnJvc25hbg==?= | last post by:
I am using C#(Vs.Net 2003) The error I am getting is... System.Xml.XmlException: This is an unexpected token. The expected token is 'EndElement' I have come to understand that this error is being caused by a character or set of characters...in the value of an xml element.
6
7540
by: Joe | last post by:
I'm getting an error when deserializing my objects: "The ObjectManager found an invalid number of fixups. This usually indicates a problem in the Formatter." I added a new object to a class that gets serialized and put the OptionalField attribute on that object. When trying to deserialize my object in an older version of our application that doesn't have this new class I get the above error but that's only when items have been added to...
0
9636
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
10139
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
9931
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...
1
7485
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
5373
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
5504
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4037
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
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2869
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.