CRM Metadata, upgrades, and strangeness

Occasionally you run into very strange issues retrieving metadata from a Dynamics CRM organization that has been through an upgrade process.

There are installations in the wild that started with v1.2 or 3.0 then were upgraded to 4.0 then 2011.

For some reason, organizations that went though this process can sometimes have incomplete metadata. I have run across this situation so infrequently that it is hard to pin down exactly what is happening, but it appears that some metadata properties contain a value of null instead of their proper value.

This seems to only appear if the organization was upgraded from CRM 1.2 or 3.0.  If the organization started off CRM 4.0 and was then upgraded to 2011, you should be fine.

I encountered a situation this week while working on a soon-to-be-released CRM documentation tool where the tool was crashing when it retrieved metadata for the Attributes (Fields).

It turns out that the AttributeMetadata.RequiredLevel property was null, when I was expecting anything but a null.

Lesson learned:

When working with CRM metadata, do not assume that there will always be a value in the attribute. Verify that the attribute is not null before attempting to access any of the attribute’s properties.  Like this:

if (attribute.RequiredLevel != null &&
    attribute.RequiredLevel.Value == AttributeRequiredLevel.SystemRequired)
    return false;


Thanks to Rhett Clinton for investing the time into helping track this down.

Leave a Reply 2 comments