BinaryFormatter to XMLSerializer... PLEASE HELP!!!

BinaryFormatter to XMLSerializer... PLEASE HELP!!!

Old forum URL: forums.lhotka.net/forums/t/7866.aspx


MonkeyBoyUK posted on Saturday, October 24, 2009

Hi All... I have got a problem when attempting to edit or add values to my objects. It happens when I add or edit an item from within my BusinessListBase object. The error is listed below.

System.Runtime.Serialization.SerializationException was unhandled by user code
  Message="Type 'WindowsApplication1.DB' in Assembly 'ICSPartyBeer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable."
  Source="mscorlib"

I checked online and Microsoft say it is because the CSLA uses the BinaryFormatter instead of XMLSerializer to serialize the object...

Just wondering if there is a new version which covers this that works with VS2005?

I tried to look into a fix by changing the code in the cs file but it comes up with another error then another one... Seems im not that good yet... Any help that you could offer would be greatly appreciated...

 

MonkeyBoyUK replied on Saturday, October 24, 2009

P.S. The Microsoft Article where i found this information is as follows :

http://support.microsoft.com/kb/818412

Many thanks again...

MonkeyBoyUK replied on Saturday, October 24, 2009

Hi All...

Right, Sorted It...

1. Added The Following to the BinaryFormatterWrapper

''' <summary>

''' Gets a reference to the underlying

''' <see cref="XmlSerializer"/>

''' object.

''' </summary>

Public ReadOnly Property Formatter() As XmlSerializer

Get

Return _formatter

End Get

End Property

 

2. Added the Entries into the App.config file to allow the XMLSerializer to be used.

<setting name="CslaSerializationFormatter" serializeAs="String">

<value>XMLSerializer</value>

</setting>

3. Then in the BinaryFormatterWrapper.vb file, I Changed

Private _formatter As New XmlSerializer(GetType(BinaryFormatterWrapper))

To

Private _formatter As New XmlSerializer(GetType(BinaryFormatterWrapper))

and obviously fixed any errors that popped up because of the type change...

When I get a spare to seconds I am gonna make this change more perminent. Would be nice if this is done in the next release unless it has been sorted already...

Great work by the way, Loving the CSLA... Makes everything so much easier... 

RockfordLhotka replied on Saturday, October 24, 2009

I don't know what you are trying to accomplish?

Generally speaking, the XmlSerializer won't work with CSLA .NET objects for several reasons:

In the .NET framework there are two categories of serializer: the open XML type, and the .NET type.

The open XML serializers (XmlSerializer, DataContractSerializer, JsonSerializer, etc) are not designed for cloning an object graph with full fidelity. They are designed for converting the public elements of an object graph into a standards-based data stream that can be interpreted by any platform or technology.

The .NET serializers (BinaryFormatter and NetDataContractSerializer) are designed for cloning an object graph with full fidelity. They are generally intended for .NET-to-.NET interactions, though technically the NDCS output is standards based (if anyone but Microsoft was crazy enough to implement the complete standard).

CSLA .NET requires the ability to create a clone of the object graph with full fidelity, and therefore requires the .NET serializers.

If you are trying to implement an open XML interface, you should read Chapter 21 of the Expert 2008 Business Objects book, where I discuss the correct way to create that type of interface.

Copyright (c) Marimer LLC