Home > Back-end >  Unable to marshal host object to interpreter space
Unable to marshal host object to interpreter space

Time:12-24

I'm getting the error "Unable to marshal host object to interpreter space" when I'm trying to run this code:

List<Schedule> currentSchedules = schedules.Where(
    x => DateTime.Today >= x.StartDate && DateTime.Today <= x.EndDate);

Can anyone help me understand why and what it means?

It should return only the schedules that have already started and not ended.

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

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

CodePudding user response:

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