CRM 2011 SDK - System.InvalidCastException: Unable to cast object of type 'Microsoft.Xrm.Sdk.Entity' to type...

This is the same issue as the one mentioned in my blog from a few days ago (Error while using the Create Method - System.ArgumentNullException: Value cannot be null)...but this time I got an InvalidCastException while trying to cast an entity instance to a proxy generated early-bound type.  Same resolution, ensure that you call EnableProxyTypes before you retrieve/update/etc early-bound type instances.

        using (OrganizationServiceProxy serviceProxy = GetProxy())
{
serviceProxy.EnableProxyTypes();
            IOrganizationService service = (IOrganizationService)serviceProxy;
return service.Retrieve(entityName, id, columSet);
}

Comments

  • Anonymous
    February 06, 2013
    Thanks, you just saved me many hours.