Custom ISerializationFormatter Feature Request

Custom ISerializationFormatter Feature Request

Old forum URL:

BrettJaner posted on Thursday, May 14, 2015

I'd like to see the ISerializationFormatter feature extended to allow applying my own implementation.  Being able to specify the type in the app.config/web.config similarly to how you provide a custom WcfProxy or DataPortalActivator would be perfect for me.  My current problem requires me to provide the BinaryFormatter with a custom SerializationBinder.  This feature would make this a lot easier.  Has this idea been tossed around at all?

JonnyBee replied on Friday, May 15, 2015


Did you look at the MobileFormatter and its supported formatters? 

BrettJaner replied on Friday, May 15, 2015

Thanks JonnyBee for your reply!

I have looked at the MobileFormatter and I don't believe it provides the extension points I need, even if I implemented my own ICslaWriter and ICslaReader.  Basically I have my own custom SerializationBinder which I need to apply to the BinaryFormatter.  This represents my custom formatter.  I have created by own WcfProxy and DataPortal so I've been able to apply my custom formatter there.  I've overridden GetClone in my BusinessBases as well.  However not sure how to provide my custom formatter to the UndoableBase for the n-level undo feature.  The further I dig, the more it seems I need this feature.

RockfordLhotka replied on Wednesday, May 20, 2015

This has not been tossed around at all.

Creating a serialized that actually works (does deserialization properly - that's the hard part) is really hard, and you are perhaps the third person to bring up the desire to do so at all.

(fwiw, the first two people said "this is easy", I warned them it was hard, then they disappeared never to be heard from again - so I'm guessing the effort broke them :)  )

I obviously haven't put any thought or analysis into how difficult it would be to allow the use of a custom type, but I imagine the changes to CSLA would be relatively small. The risk to someone providing such a type would be high, but could be mitigated through extensive testing of cloning complex object graphs, just like we do with MobileFormatter.

In other words, if this is highly important to you, and can be done with minimal change/risk to CSLA itself, I would consider accepting a pull request along this line.

BrettJaner replied on Tuesday, May 26, 2015

I completely agree.  Writing my own serialization/deserialization code would be hard and I have no interest in doing so.  I simply want to provide the BinaryFormatter with a custom implementation of a SerializationBinder.  SerializationBinder is a abstract class in BCL that has one abstract method, BindToType to aid in deserialization.  The way you apply a custom binder to a formatter is as follows:

var formatter = new BinaryFormatter();

formatter.Binder = new MyCustomBinder();

However, since CSLA controls the object initialization of its formatter, I'm unable to supply my custom binder.  So from a framework standpoint, I'd figured there would be more use cases for customizing the whole formatter, instead of just allowing a custom binder.  I'll start digging in to see how much work the change to CSLA would be.  If its simple enough, I'll send a pull request for review.

RockfordLhotka replied on Tuesday, June 09, 2015



Copyright (c) Marimer LLC