Microsoft Dynamics CRM Early Bound Entity Classes

Back to Blog Listing

Early Bound Entity Classes are used by CRM 2011 to allow the developer to use the custom objects as they are stored in CRM as objects, i.e. contact.firstname rather than Entity(“firstname”). This makes it much easier to program but it also very useful for error handling. Without Early Bound Entity classes any returned entity from the CRM API is not specifically defined but is a generic entity with unknown attributes. With generic entities if a field does not have a value set in CRM (i.e. email against a contact) then trying to access that could return in an object reference error. With the Early Bound Entity classes however, there is an instantiation process used so therefore trying to access an email against a contact where this has not been set would simply return an empty string instead of a null pointer.

Most definitions of Early Bound Entity class instructions are all set in C#, though it is true that the classes themselves must be generated using C# the following instruction shows how to integrate this with a VB.NET environment.

Using Early Bound Entity Classes

For reference please see

To use these classes please use the following steps:

Ensure you have installed the Microsoft CRM SDK



Generate your device ID

  • Open command prompt (as administrator)
  • navigate to the folder containing your SDK files
  • navigate to sdk\tools\deviceregistration\bin\debug
  • use the following command "deviceregistration.exe /operation:Register"
  • this will show a device ID and password. Make note of these values

 ScreenHunter_74 Nov. 08 11.36


Generate your class files

  • Open command prompt (as administrator)
  • navigate to the folder continaing your SDK files
  • navigate to sdk\bin
  • use the following command substituting each param for your own information:
    • crmsvcUtil.exe /url:<url>/XRMServices/2011/Organization.svc /o:<name>.cs /n:<namespace> /u:<username> /p:<password> /di:<device> /dp:<devicepassword>
  • this will generate your file in the sdk\bin folder.

ScreenHunter_75 Nov. 08 11.39 


Add Entity Classes to your project

  • Create a new C# Class library in your project
  • Ensure it has the same runtime and cpu target as the rest of your project
  • Copy the generated class file to your project
  • Ensure you reference the necessary Microsoft.CRM and Microsoft.XRM assemblies
  • Add a reference to System.Runtime.Serialization
  • Build project
  • Copy project .dll from the bin/debug folder of your class library and add it as a reference to the necessary VB projects.

ScreenHunter_76 Nov. 08 11.40

ScreenHunter_77 Nov. 08 11.41 


Using Entity Classes

  • Once you have your reference in place you can use it in the following way:
  • Ensure your connection class (the one that returns your service usually) returns an OrganizationServiceProxy
  • Then surround your call with a using
  • First line inside your using should be .EnableProxyTypes
  • Cast your proxy to the necessary IOrganization service
  • Make your call as usual using .retrieve
  • Cast your returned entity to the required custom type and then can use as a normal entity with intellisense for all attributes

ScreenHunter_78 Nov. 08 11.45 


12 Nov 2013

About the Author

James CTwo is our blogging alter ego for the Dynamics CRM and Web experts here at C2. We have a passion for anything CRM, Web Design or Social Media. We love writing about it! Find us on YouTube & Twitter.

comments powered by Disqus

Our White Papers

Discover the content that matters to you on business transformation. Explore how you can drive customer engagement, empower your team, optimise your businesses and revolutionise your products with the next digital revolution. For more information visit our white paper library.


C2 Newsletter

Our newsletter is sent on a quarterly basis, offering detailed insights into all aspects of business transformation with Microsoft cloud technologies. We also promote upcoming events and special offers throughout the year. Sign up to get involved today.

Dynamics 365 Office 365 Power BI Silver Partner