crm Archives - Byron Salau

FIX: Unable to cast object of type ‘Microsoft.Xrm.Sdk.Entity’ to type “Your Entity Class”

Posted by | c# | One Comment

If you ever come accross this while using the Microsoft Dynamics SDK Proxy

Unable to cast object of type 'Microsoft.Xrm.Sdk.Entity' to type "Your Entity Class"

The solution

Where you create your service proxy instance, make sure you ‘Enable Proxy Types’ (see line 2)

example


OrganizationServiceProxy orgProxy = new OrganizationServiceProxy(organizationUri, null, credentials, null);
orgProxy.EnableProxyTypes();

IOrganizationService service = (IOrganizationService)orgProxy;