Unable to marshal host object to interpreter space

Viewed 1189

I'm trying to run this code, to get only the schedules that already started and not ended:

schedules.Where(x=> DateTime.Today >= x.StartDate && DateTime.Today <= x.EndDate)

schedules is of type List<Schedule>

and the object Schedule has these 2 properties StartDate and EndDate, both of type DateTime.

So, on this line, I'm getting the error "Unable to marshal host object to interpreter space".

Can anyone help me understand why and what it means?

I tried to use DateTime.Compare() or changing DateTime.Today to DateTime.Now, nothing helps.

1 Answers

The solution is to set a variable with the value DateTime.Today and pass it to the Linq.

var today = DateTime.Today;
schedules.Where(x=> today >= x.StartDate && today <= x.EndDate)

Still have no explanation for this, but it works.

Related