CRM 2011: Early Binding C#- error while retrieve and save data

If you’re using Early Binding with CRM 2011 and facing one of the following issues… you’ve landed on the right page!!

While retrieving the data using LINQ:
Exception Type: ArgumentException
Message: Object of type ‘Microsoft.Xrm.Sdk.Entity’ cannot be converted to type ‘XXX’.

OR

Updating the data using LINQ:
Exception Type: SaveChangesException
Message: An error occured while processing this request.
Inner Exception: {“Value cannot be null.rnParameter name: value”}

You probably forgot to add a behavior to the OrganizationServiceProxy object given as below.

serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());

This statement is required to enable early-bound type support.

Enjoy!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s