Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type

The problem is that topAgents is dynamic – so your ToList() call is dynamic, and so is Select. That has issues that:

  1. you can’t use lambda expressions for dynamic calls like this;
  2. dynamic calls don’t find extension methods anyway.

Fortunately, the operations don’t need to be dynamic just because the element type is dynamic. You could use:

IEnumerable<dynamic> topAgents = ...;

… or just use var. Both of those should be fine.

Leave a Comment