DataContractSerializer does not accept generic list of guids when serializing a mobileobject

DataContractSerializer does not accept generic list of guids when serializing a mobileobject

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


mliceaga posted on Thursday, September 23, 2010

I´m working in a project using SL4, BXF, Csla.Silverlight, Csla, Csla.Xaml, Csla.Xaml.Silverlight and unitdriven for the unit tests.

Many of the objects (if not all) of the business layer have properties like this:

public static PropertyInfo<List<Guid>> BLAHListProperty = RegisterProperty<List<Guid>>(new PropertyInfo<List<Guid>>("BLAH", "BLAH"));
        public List<Guid> BLAHList
        {
            get { return GetProperty(BLAHListProperty); }
            set { SetProperty(BLAHListProperty, value); }
        }

When trying to save the objects that had these kind of properties (basically a generic List of Guids) I got an error that said that the DataContractSerializer couldn´t serialize it.

We´re using CslaSource-4.0.1-100828

In the file: Csla\Serialization\Mobile\MobileFormatter.cs

from lines 148 to 153 we had to make the following change in order to allow this.

    private DataContractSerializer GetDataContractSerializer()
    {
      return new DataContractSerializer(
        typeof(List<SerializationInfo>),
        new Type[] { typeof(List<int>), typeof(byte[]), typeof(DateTimeOffset), typeof(List<Guid>) });
    }

What do you think about this? I know I shouldn´t be modifying the very core of CSLA, but I couldn´t figure out another workaround. Can you think of something else? Or otherwise, include in the next version? ;)

Regards,

cds replied on Thursday, September 23, 2010

Just off the top of my head, try using MobileList<T> instead of List<T>

Copyright (c) Marimer LLC