Serialize failure after update to 5.5.3 #3273
-
Describe the bug But still I get an excption when saving a quite big object to the database. See Stack Trace below. The object mentioned in the stacktrace (IncompleteDateTime) we use a lot in our code and has never been a problem. And added an extra unittest for it to test the serializabillity and that succeedd as well. Even build an integration test with the same message and all the steps that are done in the MessageProcessor. But whereas the MessageProcessor fails, the integration test can save the object to the database. Does anyone have a hint for me why this exception is thrown after this update? And not in the old framework/CSLA and in the same code in the integration test? Version and Platform Code that Fails using System;
[Serializable]
public class IncompleteDateTime : IComparable, IComparable<IncompleteDateTime>
{
public IncompleteDateTime()
{
}
public IncompleteDateTime(DateTime? value)
{
Value = value;
}
public IncompleteDateTime(DateTime? value, string incompleteness)
{
Value = value;
Incompleteness = incompleteness;
}
public DateTime? Value { get; set; }
public string Incompleteness { get; set; }
} Stack Trace or Exception Detail
Additional context |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
My guess is that you need to look into the nullable DateTime field. It may be that the serialization has changed to MobileFormatter from BinaryFormatter. MobileFormatter will only be able to format primitive types. It may be that a nullable type is seen as an object and not as a DateTime. |
Beta Was this translation helpful? Give feedback.
-
Thanks! I had to add the public void GetState(SerializationInfo info)
{
if (Value.HasValue)
{
info.AddValue(nameof(Value), Value.Value);
}
if (Incompleteness != null)
{
info.AddValue(nameof(Incompleteness), Incompleteness);
}
}
public void GetChildren(SerializationInfo info, MobileFormatter formatter)
{
// Intentionally left empty
}
public void SetState(SerializationInfo info)
{
if (info.Values.ContainsKey(nameof(Value)))
{
this.Value = (DateTime)info.Values[nameof(Value)].Value;
}
if (info.Values.ContainsKey(nameof(Incompleteness)))
{
Incompleteness = info.Values[nameof(Incompleteness)].Value?.ToString();
}
}
public void SetChildren(SerializationInfo info, MobileFormatter formatter)
{
// Intentionally left empty
} Now I have only one question left: In all of our other projects (which where converted earlier) we've used this class without the interface. Why didn't we run into problems there? 🤔 |
Beta Was this translation helpful? Give feedback.
My guess is that you need to look into the nullable DateTime field. It may be that the serialization has changed to MobileFormatter from BinaryFormatter. MobileFormatter will only be able to format primitive types. It may be that a nullable type is seen as an object and not as a DateTime.