尝试使用AppFabric存储会话,但收到错误:键入' System.Linq.Enumerable + WhereSelectListIterator未标记为可序列化

时间:2014-07-10 14:54:42

标签: asp.net appfabric

输入'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]]'在Assembly'System.Core,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'未标记为可序列化。

有没有人有想法序列化上述内容?

1 个答案:

答案 0 :(得分:0)

听起来你要么试图在会话中存储一个匿名类型:

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

这不可序列化,因为anonymous types can't be serialised as XML

或者,如果要在Select方法中创建已知类型,则必须先调用ToList才能序列化:

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

否则序列化程序必须序列化尚未枚举的IEnumerable,这就是它失败的原因。