Serialization between different versions of the framework

A

Alexander

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;}
}
}
 
N

Nicholas Paldino [.NET/C# MVP]

Alexander,

This isn't necessarily related to different versions of the framework as
much as it is related to differences between the class type you are trying
to deserialize into. The metadata definition has changed, and isn't in sync
with what was found in the stream you are trying to deserialize from. Since
this is a framework type, you have little choice but to use serialized
versions of that type.

However, if it was your own type, you could implement custom
serialization, and perform a check to see what is available in the
SerializationInfo class. If the values you need are not there, then you can
set to default values.

The serialization model in .NET 2.0 will include an OptionalField
attribute which when set on a field, will not cause an error if the
information does not exist in the serialized stream. This is to stem errors
from versioning, of course.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Alexander said:
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;}
}
}
 
A

Alexander

Yes, but error in "System.Collections.Comparer" wich contains in
ArrayList(Conditions and Actions inherit it), how can i control
serialization of ArrayList?


Nicholas Paldino said:
Alexander,

This isn't necessarily related to different versions of the framework
as much as it is related to differences between the class type you are
trying to deserialize into. The metadata definition has changed, and
isn't in sync with what was found in the stream you are trying to
deserialize from. Since this is a framework type, you have little choice
but to use serialized versions of that type.

However, if it was your own type, you could implement custom
serialization, and perform a check to see what is available in the
SerializationInfo class. If the values you need are not there, then you
can set to default values.

The serialization model in .NET 2.0 will include an OptionalField
attribute which when set on a field, will not cause an error if the
information does not exist in the serialized stream. This is to stem
errors from versioning, of course.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Alexander said:
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;}
}
}
 
N

Nicholas Paldino [.NET/C# MVP]

Alexander,

That's the thing, you can not. If you need to control this, you might
have to use a different class (Comparer is an implementation of IComparer,
right? Use a different implementation that you control) altogether.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Alexander said:
Yes, but error in "System.Collections.Comparer" wich contains in
ArrayList(Conditions and Actions inherit it), how can i control
serialization of ArrayList?


Nicholas Paldino said:
Alexander,

This isn't necessarily related to different versions of the framework
as much as it is related to differences between the class type you are
trying to deserialize into. The metadata definition has changed, and
isn't in sync with what was found in the stream you are trying to
deserialize from. Since this is a framework type, you have little choice
but to use serialized versions of that type.

However, if it was your own type, you could implement custom
serialization, and perform a check to see what is available in the
SerializationInfo class. If the values you need are not there, then you
can set to default values.

The serialization model in .NET 2.0 will include an OptionalField
attribute which when set on a field, will not cause an error if the
information does not exist in the serialized stream. This is to stem
errors from versioning, of course.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Alexander said:
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;}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top