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.

Trackback

2 comments untill now

  1. [...] to Rhett Clinton for investing the time into helping track this down. You just finished reading CRM Metadata, upgrades, and strangeness! Consider leaving a comment!Follow me on Twitter @mitchmilam. Read my new book: Dynamics Deep Dive: [...]

  2. ping back xrmSchool.com

Add your comment now

Sign up for our new KnowledgeBits service and get news, tips and tricks and more, delivered straight to your inbox.