Serialization

  • Thread starter Thread starter Alexander
  • Start date Start date
A

Alexander

There was such problem,

At compilation with SP1 (dotnetfx11SP1)

On computers without him{it} ÎÅÄÅÓÅÒÉÁÌÉÚÕÀÔÓÑ some objects.

For example (System. Collections. Comparer) and together with it{him} and
all objects in which it{he} is used, for example ArrayList

Whether it is possible to bypass it somehow
 
Alexander said:
There was such problem,

At compilation with SP1 (dotnetfx11SP1)

On computers without him{it} ÎÅÄÅÓÅÒÉÁÌÉÚÕÀÔÓÑ some objects.

For example (System. Collections. Comparer) and together with it{him} and
all objects in which it{he} is used, for example ArrayList

Whether it is possible to bypass it somehow

I'm afraid your question isn't very clear at all.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
 
When i store rule on PC with .NET.SP1 i cant restore them from PC without
SP1.
An i get this Error:

System.Runtime.Serialization.SerializationException:
Possible Version mismatch. Type System.Collections.Comparer has 1 members,
number of members deserialized is 0.

at
System.Runtime.Serialization.Formatters.Binary.ReadObjectInfo.GetMemberTypes(String[]
inMemberNames)
at System.Runtime.Serialization.Formatters.Binary.ObjectMap..ctor(String
objectName, String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[]
typeInformationA, Int32[] memberAssemIds, ObjectReader objectReader, Int32
objectId, BinaryAssemblyInfo assemblyInfo, SizedArray
assemIdToAssemblyTable)
at System.Runtime.Serialization.Formatters.Binary.ObjectMap.Create(String
name, String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[]
typeInformationA, Int32[] memberAssemIds, ObjectReader objectReader, Int32
objectId, BinaryAssemblyInfo assemblyInfo, SizedArray
assemIdToAssemblyTable)
at
System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped
record)
at
System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryHeaderEnum
binaryHeaderEnum)
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
at
System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler
handler, __BinaryParser serParser, Boolean fCheck, IMethodCallMessage
methodCallMessage)
at
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream
serializationStream, HeaderHandler handler, Boolean fCheck,
IMethodCallMessage methodCallMessage)
at
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream
serializationStream, HeaderHandler handler)
at
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream
serializationStream)
at OptOutManager.Rules.Get(Int32 idx) in D:\Projects\Rules\Rules.cs:line
33

Whether it is possible to bypass it somehow

[Serializable]
public class Rule: ISerializable{
public bool Checked;
public string Name;
public Conditions conditions;
public Actions actions;
public string Description;
// Some methods declarations
}

[Serializable]
public class Conditions: ArrayList {
public ConditionsOperatorEnum Operator = ConditionsOperatorEnum.Or;

new public Condition this[int index]{
get {return (Condition)base[index];}
set {base[index] = value;}
}
// Some methods declarations
}

[Serializable]
public class Condition: ISerializable {
public bool Checked;
public string field;
public string word;
public ConditionType Type;
public bool MatchCase;
// Some methods declarations
}

[Serializable]
public class Action {
public bool Checked;
public ToDo todo;
public ComposeEmail sendEmail;
public Script script;
public DatabaseAction dbAction;
public ListsSubUnsub listsSubUnsub;
// Some methods declarations
}

[Serializable]
public class Actions: ArrayList {
public new Action this[int index]{
get {return (Action)base[index];}
set {base[index] = value;}
}
}
 
Alexander said:
When i store rule on PC with .NET.SP1 i cant restore them from PC without
SP1.

Right. Effectively, you've got different versions of ArrayList. I'm not
entirely surprised serialization doesn't work in this case, to be
honest. Not sure that the error message is as useful as it could be,
but I think it's generally unlikely that serialization will work
between different versions of the framework. Then again, I'm not a
serialization expert by any stretch of the imagination.
 
Jon Skeet said:
Right. Effectively, you've got different versions of ArrayList. I'm not
entirely surprised serialization doesn't work in this case, to be
honest. Not sure that the error message is as useful as it could be,
but I think it's generally unlikely that serialization will work
between different versions of the framework.

I would think that if the serialized bits are going to be persisted to disk
it would be best (safest) policy to do your own serialization. You would
also want to be sure to store a version number in the image so that later
versions can restore successfully.

-- Alan
 
Back
Top