When using the CRM 2011 SDK to generate early-bound classes, you will notice that the crmsvcvutil.exe utility no longer generates these classes using the display names of entities, but rather their schema names. For some developers this is preferable, but I needed to update an entities file that was originally generated against a CRM 4.0 organization that was being upgraded to CRM 2011. To refactor the solution to use schema names would not have been an insignificant effort, and so I decided to dig in and find out how to force the crmsvcutil.exe utility to use display names.

I began by reading this article, which details how to create extensions for the crmsvcutil.exe utility. The key here is the interface INamingService, which the utility uses to determine the names for the objects it generates.

I first created a class library project named CrmSvcUtil Extensions for housing any classes I would create to extend the utility. You must add references to the Microsoft.Xrm.Sdk assembly, as well as to the crmsvcutil.exe utility itself (additionally you will require a reference to System.Runtime.Serialization).


I then added a class to the project named DisplayNamingService, which implements INamingService:

Next we need to add a variable of type INamingService that will act as our default naming service for when we don’t want to override the default behavior. We also need to add a constructor that takes the default service as its parameter. We then use that default naming service in all of our interface methods so that the new naming service functions at least the same as the one that crmsvcutil.exe utilizes. The DisplayNamingService should now look like this:

We then want to override the default naming service’s behavior for the methods GetNameForAttribute, GetNameForEntity, and GetNameForEntitySet in order to generate the entity/attribute display name if available.

First we modify the GetNameForEntity method to check if the DisplayName.UserLocalizedLabel property is null for the entityMetadata parameter. We must check the UserLocalizedLabel property since this is the label of the DisplayName for that entity as it is displayed in the current user’s language. We pass the Label property of the UserLocalizedLabel to the method FormatDisplayName to remove any illegal characters or spaces. GetNameForEntity should now look like this:

We then do the same for the GetNameForEntitySet method, though instead of the DisplayName property of the entityMetadata parameter, we instead check the DisplayCollectionName property, which contains the value set for the plural name of the entity:

Lastly we modify the GetNameForAttribute method, which examines the DisplayName for the attributeMetadata parameter this time, checking once again for the UserLocalizedLabel:

The completed DisplayNamingService should now look like this:

Build the solution, then look in the bin folder for the compiled CrmSvcUtil Extensions assembly, as well as the crmsvcutil.exe utility. You can run the crmsvcutil.exe with the DisplayNamingService by using the switch /namingservice:”CrmSvcUtil_Extensions.DisplayNamingService, CrmSvcUtil Extensions” and your entities will be generated using the display name instead of the schema name.

Like this post? Share it!