0
votes

Type 'System.Linq.Enumerable+WhereSelectListIterator`2[[Services.Client.DomainValueMEMBERFIELDS, Services.Client, Version=12.2.4.0, Culture=neutral, PublicKeyToken=null],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' in Assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable.

Does anyone have idea to serialize the above thing?

1

1 Answers

0
votes

It sounds like either you're trying to store an anonymous type in the session:

var somethingInTheSession = aCollection
      .Where(x => ??)
      .Select(x => x.Id, x.Name);

That isn't serializable because anonymous types can't be serialised as XML

Or, if you are creating a known type in the Select method, you would have to call ToList before it can be serialized:

var somethingInTheSession = aCollection
   .Where(x => ??)
   .Select(x => new Person { Id = x.Id, Name = x.Name)
   .ToList();

Otherwise the serializer has to serialise an IEnumerable which hasn't been enumerated yet, which is why it fails.