Unable to cast object of type Microsoft.XrmSdk.Entity

You’ll likely encounter early bound types when developing workflows, plugins or anything else which calls the Dynamics 365 SDK. These are basically generated classes which come from Dynamics. You can generate them using the CrmSvcUtil.exe. If you’ve ever done anything with T4 templates you can think of them as that or a really poor substitute for F# type providers.

One of the nice things about these is that in conjunction with the CreateQuery method on the OrganizationServiceContext you can write LINQ queries instead of fumbling about with QueryExpression.

The problem here is that the SDK doesn’t by default understand these classes which extend Entity. The fix is pretty simple. When creating the OrganizationServiceProxy add a ProxyTypesBehavior to the endpoint behaviours