Wednesday, January 4, 2012

CRM 2011 import error: managed solution cannot overwrite the EntityMap component

Solutions are a very important feature in crm 2011, with a multitude of uses. One of the most common ways to utilize solutions is to create packaged customizations that can be later distributed. The publisher that is associated with the solution can set the managed properties to control the level of customizable actions the end user can have. For example, you can get to a very granular level of checking if a particular view is end user customizable, or not.

Solutions are "layered" when they are imported, based on the order of import. In this post, I will focus on a particular error during an import of a managed solution.

If the import is done using the UI or with code (like a console or form application), the error will be similar to this message:

A managed solution cannot overwrite the EntityMap component with Id=b925c093-77c6-474e-b7ac
-dae44d569c53 which has an unmanaged base instance.  The most likely scenario for this error is that an unmanaged solution has installed a new unmanaged EntityMap component on the 
target system, and now a managed solution from the same publisher is trying to install 
that same EntityMap component as managed.  This will cause an invalid layering 
of solutions on the target system and is not allowed.

In SQL server management studio, you can query the entity map table to find the exact entities involved in the error.
select TargetEntityName, SourceEntityName, * from EntityMap
where EntityMapId='b925c093-77c6-474e-b7ac-dae44d569c53'

In this case, there was a contact to lead mapping that existed in the unmanaged solution. Below is a snippet from the customizations.xml file, that is obtained from exporting the core solution and unzipping the folder contents.

  <EntityMaps>
    <EntityMap>
      <EntitySource>contact</EntitySource>
      <EntityTarget>account</EntityTarget>
      <AttributeMaps />
    </EntityMap>
    <EntityMap>
      <EntitySource>contact</EntitySource>
      <EntityTarget>lead</EntityTarget>
      <AttributeMaps />
    </EntityMap>
  </EntityMaps>

My managed solution also had an EntityMap node identical to the unmanaged core solution, resulting in the error. To get around it, the solution is to remove the offending <EntityMap> node from the customizations.xml file that is part of the import zip, in this case the following:

    <EntityMap>
      <EntitySource>contact</EntitySource>
      <EntityTarget>lead</EntityTarget>
      <AttributeMaps />
    </EntityMap>

Package the files in a zip folder and import the solution. You will not see the error message and the import will complete successfully.

The important thing to remember here is that the import error does not occur when the entitymap duplicate is part of a managed solution. It will make a little more sense when you follow along the steps below, first to create a entity map conflict, and then resolve the conflict without mucking around xml files.

So here are the steps to produce the error:

1. Create a solution, and add entity "contact" and "Lead".

2. Go to solution components/ contact/ 1:N Relationships and click on New 1-to-Many Relationship.























3. Create a relationship to Lead entity. Fill out the values as in the screen shot below.

























4. Save and close the new relationship window. Publish all customizations.

5. Import a managed solution that also has a contact mapped to the lead entity. You will see the following error message during import. Download the log file to see more details.
















Now here are the steps to get around this error without having to change any customizations file, IF you can move the entity out as a managed solution.

1. Create a solution, and add entity "contact" and "Lead".

2. Go to solution components/ contact/ 1:N Relationships and click on New 1-to-Many Relationship.

3. Create a relationship to Lead entity.

4. Save and close the new relationship window. Publish all customizations.

5. Export the solution in managed form.

6. Import the solution from step 5 into another organization.

7. Import a second managed solution that also has a contact mapped to the lead entity. The import will complete succesfully.


As a rule of thumb, I would strongly advice adding every solution as a managed solution, even if it is an internal project and the publisher is not an ISV. But in case you are upgrading from v4 to crm2011, and thus carrying over all customizations as part of the core solution, I hope this post helps figure out this offbeat import error!

1 comment:

  1. A really late comment, but do you know a way to solve this issue without adjusting the customizations.xml?

    ReplyDelete