CrmDuplicateRecordException Error 0x80040237 “Cannot insert duplicate key.” during import of CRM Solution

So when you import a solution, then this leads to error 0x80040237 “Cannot insert duplicate key.”? Then download the solution import XML log file, open in Excel, and have a look at the name of the troubled entity.


Then unzip solution ZIP and open the customizations.xml. Find the troubled entity, the easiest is to search for:

<entity Name="[yourentity]">

Within this entity you should find something similar to this:

<CustomControlDefaultConfigs>

        <CustomControlDefaultConfig>

          <PrimaryEntityTypeCode>10046</PrimaryEntityTypeCode>

          <CustomControlDefaultConfigId>{924314e7-3e47-e614-80de-fc15b4269a54}</CustomControlDefaultConfigId>

          <ControlDescriptionXML><controlDescriptions /></ControlDescriptionXML>

          <IntroducedVersion>2016.07.6.1</IntroducedVersion>

        </CustomControlDefaultConfig>

      </CustomControlDefaultConfigs>

The PrimaryEntityTypeCode is from the origin/source environment. In the target environment, the PrimaryEntityTypeCode is different. This usually isn’t an issue, but somehow the system can get confused. Most likely you’ll find that the Guid for this CustomControlDefaultConfigId appears for two different PrimaryEntityTypeCodes in the target system. You can confirm this using this query:

SELECT PrimaryEntityTypeCode, * FROM CustomControlDefaultConfigBase WHERE CustomControlDefaultConfigId = '[your guid]'

If you indeed see records with different PrimaryEntityTypeCode and the same CustomControlDefaultConfigId, then this is indeed the issue. The one which doesn’t match the code from the XML file, in this example 10046, is the one from the origin environment, the other from the target environment. We should get rid of the one which matches the origin environment.

DELETE FROM CustomControlDefaultConfigBase WHERE CustomControlDefaultConfigId = '[your guid] AND PrimaryEntityTypeCode = '[PrimaryEntityTypeCode from customizations.xml]'

If after fixing this bug you’re faced with another error on the same entity, with the message ‘There should not be more than one component instance for a solution being upgraded’, then it’s getting more challenging. My advice? Contact Microsoft Support..

5 comments:

Kanhasoft said...

Are you looking for CRM Solution Developer? Kanhasoft offers custom CRM Software Development to the offshore clients from countries UK, Canada, USA, Japan, Australia, Sweden, Norway, Switzerland, New Zealand, Germany, South Africa and 45 more.

Karla said...

Lovely post. Learned so much from it. Many Many thanks. Cheers.

steve said...


الرائد تقدم خدمات تطهير و تعقيم خزانات المياه فى جدة و مكة لاننا :
افضل شركة غسيل خزانات بجدة
و افضل شركة غسيل خزانات بمكة
للمزيد قم بزيارة
افضل شركة تنظيف منازل

Packers and Movers Bangalore said...

Packers and Movers Bangalore as a Services providing company can make all the difference to your ###Home Relocation experience. Bangalore based Company which offers versatile solutions, Right team that easily reduce the stress associated with a ✔✔✔Household Shifting, ***Vehicle Transportation. we help things run smoothly and reduce breakages and offer you seamless, Affordable, Reliable Shifting Services, Compare Shifting Charges @
Packers And Movers Bangalore

Packers and Movers Chennai said...

Packers and Movers Chennai Give Safe and Reliable ***Household Shifting Services in Chennai with Reasonable ###Packers and Movers Price Quotation. We Provide Household Shifting, Office Relocation, ✔✔✔Local and Domestic Transportation Services, Affordable and Reliable Shifting Service Charges @
Packers And Movers Chennai