无法将主机对象编组到解释器空间

SeR*_*eGa 4 .net c# linq

我正在尝试运行此代码,以仅获取已经开始但未结束的时间表:

schedules.Where(x=> DateTime.Today >= x.StartDate && DateTime.Today <= x.EndDate)
Run Code Online (Sandbox Code Playgroud)

schedules属于类型List<Schedule>

并且该对象Schedule具有这 2 个属性StartDateEndDate,均为类型DateTime

因此,在这一行中,我收到错误“无法将主机对象编组到解释器空间”。

谁能帮助我理解为什么以及这意味着什么?

我尝试使用DateTime.Compare()或更改DateTime.TodayDateTime.Now,但没有任何帮助。

SeR*_*eGa 8

解决方案是使用值设置一个变量DateTime.Today并将其传递给 Linq。

var today = DateTime.Today;
schedules.Where(x=> today >= x.StartDate && today <= x.EndDate)
Run Code Online (Sandbox Code Playgroud)

对此仍然没有任何解释,但它确实有效。