Cannot Serialize Decimal Array Property

Cannot Serialize Decimal Array Property

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


Gareth posted on Wednesday, August 26, 2009

Hi, I have some decimal[] properties in my Silverlight business object and I'm getting some serialization errors, as shown below.

I've defined my property like...

private static PropertyInfo(decimal[]) SellPriceProperty = RegisterProperty(decimal[])(c => c.SellPrice);
public decimal[] SellPrice
{
get { return GetProperty(SellPriceProperty); }
set { SetProperty(SellPriceProperty, value); }
}

and I'm initialising the array length in the DataPortal Create method.

I'm not sure how to tell it how to serialize the property. Can someone point me in the right direction?

Thanks,
Gareth.


---------------------------
Oops
---------------------------
An error has occured:

System.Runtime.Serialization.SerializationException: Type 'System.Decimal[]' with data contract name 'ArrayOfdecimal:http://schemas.microsoft.com/2003/10/Serialization/Arrays' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.

at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeAndVerifyType(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, Boolean verifyKnownType, RuntimeTypeHandle declaredTypeHandle)

RockfordLhotka replied on Wednesday, August 26, 2009

It appears that Decimal isn't a type that is natively known to the DataContractSerializer. Or at least it can't understand an array of them.

You'll need to change that array to be a MobileList<T> - hopefully that works. If not, you'll need to create your own type that implements IMobileObject (which is a bit tricky).

The reason for all this, is that there isn't a BinaryFormatter or NDCS in Silverlight, so we had to create our own serializer for CSLA .NET for Silverlight. Since we don't own the .NET or SL platforms, our serializer has limitations you don't find in BF/NDCS...

Gareth replied on Thursday, August 27, 2009

Thanks Rocky, that does appear to have sorted the problem.

Regards,
Gareth.

Copyright (c) Marimer LLC