473,242 Members | 1,497 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,242 software developers and data experts.

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();
SerializationTest(fooA);
private void SerializationTest(object o){
FooA o = new FooA;
BinaryFormatter formatter = new BinaryFormatter();
System.IO.MemoryStream memStream = new System.IO.MemoryStream();
try{
formatter.Serialize(memStream, o);
memStream.Seek(0, System.IO.SeekOrigin.Begin);
object clone = formatter.Deserialize(memStream);
}finally{
memStream.Close();
}
}


using System;
using System.Collections;

namespace TestDeserializationIssue01
{
[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.IsSynchronized;*/}
}
public int Count {
get {return 0;/*return _hash.Count;*/}
}
public void CopyTo(Array array, int index) {
/*_hash.Values.CopyTo(array, index);*/
}

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

public IEnumerator GetEnumerator() {
return null; /*return _hash.Values.GetEnumerator();*/
}
}
}
Jul 21 '05 #1
3 1625
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(System.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.kolloen.no> escribió en el mensaje
news:e7**************@tk2msftngp13.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
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...
1
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...
2
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....
3
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...
3
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...
5
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...
3
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...
0
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...
6
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...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.