Dynamics CRM 2011 – Early vs. Late Binding Overview

Roshan Mehta, 04 May 2012

Developers have two options when writing code for Microsoft Dynamics CRM 2011 – early binding and late binding. The choice comes down to personal preference, but there are several advantages and disadvantages with both options. 
 Dynamics CRM 2011 – Early vs. Late Binding Overview

Early Binding

The Microsoft Dynamics CRM 2011 Software Development Kit ships with a tool (CrmSvcUtil) which can automatically generate helper classes to make it easier to work with your CRM entities and their attributes. This provides type checking at compile time, which eliminates the chance of running into InvalidCastExceptions during execution of your custom code. It also lets developers take advantage of intellisense by suggesting names for entities, attributes, and relationships. This can speed up development time by removing the risk of spelling mistakes.

Every time you make a customization change in your system, you will need to run the CrmSvcUtil tool again to ensure that the latest entities, attributes, and relationships are available in your custom applications. The size of the generated file can be large depending on the complexity of your system.

Late Binding

Late binding involves the use of the generic “Entity” class which can manage objects of any entity type. For example, we can use the “Entity” object to programmatically create Accounts, Contacts, Leads, or Cases. Type checking is performed at runtime, so developers must explicitly cast attribute values correctly otherwise the custom code will fail during execution. Developers need to be familiar with the late binding syntax as there is no intellisense available.