PC Review


Reply
Thread Tools Rate Thread

Deserialization bug, workaround or fix desperatly needed

 
 
TEK
Guest
Posts: n/a
 
      20th Apr 2005
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();*/
}
}
}


 
Reply With Quote
 
 
 
 
TEK
Guest
Posts: n/a
 
      20th Apr 2005
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());
}
}


 
Reply With Quote
 
TEK
Guest
Posts: n/a
 
      20th Apr 2005
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


 
Reply With Quote
 
Fernando Callejon
Guest
Posts: n/a
 
      21st Apr 2005
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:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
R:Base to Access Guru Desperatly Needed! TheNovice Microsoft Access External Data 4 16th Sep 2009 08:00 PM
NotifyIcon - OwnderDraw Event Workaround needed Trevor Benedict R Microsoft VB .NET 4 24th May 2007 05:31 PM
lost xp home disc need it to access net help desperatly needed =?Utf-8?B?bmVzcw==?= Windows XP Performance 1 14th Jan 2007 12:58 AM
Deserialization bug, workaround or fix desperatly needed TEK Microsoft Dot NET 3 21st Apr 2005 03:59 AM
possible DATEVALUE bug, workaround needed Eliezer Microsoft Excel Worksheet Functions 9 6th Feb 2004 02:09 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:38 PM.