StakeTrace showing:
at Csla.Core.UndoableBase.get_EditLevel()
at Csla.Core.BusinessBase.get_FieldManager()
at Csla.Core.BusinessBase.FieldDataDeserialized()
at Csla.Core.BusinessBase.OnDeserializedHandler(StreamingContext context)
at System.Runtime.Serialization.SerializationEvents.InvokeOnDeserialized(Object obj, StreamingContext context)
at System.Runtime.Serialization.ObjectManager.RaiseOnDeserializedEvent(Object obj)
at System.Runtime.Serialization.ObjectManager.RegisterObject(Object obj, Int64 objectID, SerializationInfo info, Int64 idOfContainingObj, MemberInfo member, Int32[] arrayIndex)
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.RegisterObject(Object obj, ParseRecord pr, ParseRecord objectPr, Boolean bIsString)
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ParseObjectEnd(ParseRecord pr)
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Parse(ParseRecord pr)
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)
When running project in Debug Csla.Core.UndoableBase._stateStack is null when function UndoableBase.ResetChildEditLevel(_fieldManager, this.EditLevel, this.BindingEdit); getting value of this.EditLevel
It seems problem with binary objects deserialization. Any idea how to fix that problem?
Thanks
Probably upgrade to 3.8.2 - there have been a lot of bug fixes since 3.6...
The same problem for 3.8.2 version
One of the ways to fix that problem is to add some code in
public abstract class UndoableBase
{
...
...
...
[System.Runtime.Serialization.OnDeserializing]
private void OnDeserializing(System.Runtime.Serialization.StreamingContext context)
{
if (_stateStack == null) _stateStack = new Stack<byte[]>();
}
}
Any comments and suggestions how to do it in best way would be appreciated.
Thanks
I would like to understand the specific sequence of events that causes the exception. There is something about your object, or object usage, that is not in my unit tests. Can you describe the specific circumstances that are causing this exception?
As I understand from CSLA code it's happening for every object of BusinessBase based class that using Custom Serialization and serialize only that class fields
when trying to deserialize object using BinaryFormater
BinaryFormatter f = new BinaryFormatter();
using(Stream s = GetInputStreamByID(id)){
object temp = f.Deserialize(s); <= throws NullReferenceExceprion with StakeTrace showing above
.......
CSLA code:
BusinessBase
[OnDeserialized()]
private void OnDeserializedHandler(StreamingContext context)
{
...............................
FieldDataDeserialized();
}
UndoableBase
[NotUndoable()]
private Stack<byte[]> _stateStack = new Stack<byte[]>();
[EditorBrowsable(EditorBrowsableState.Never)]
protected int EditLevel
{
get { return _stateStack.Count; }
}
When BinaryFormater call OnDeserializedHandler() for deserialized object it appears that _stateStack has Null value
What do you mean by "Custom serialization"? Are you explicitly implementing ISerializable to override the standard serialization behaviors?
Yes. It's like this:
[Serializable]
public class MyClass : BusinessBase<MyClass>, ISerializable, ...
{
public void GetObjectData(
SerializationInfo info,StreamingContext context)
{
//serialize only MyClass fields
}
protected MyClass(SerializationInfo info,StreamingContext context)
{ //deserialize only MyClass fields
}
public MyClass()
{}
}
In that case you are kind of on your own - supporting custom serialization is outside the scope of basic CSLA functionality.
Copyright (c) Marimer LLC