locked
KeyNotFoundException on Upgrade from CRM 4.0 to 2011 (Relationship) RRS feed

  • Question

  • I have been searching for a while for a resolution to this problem. I am attempting to upgrade from 4.0 to 2011 and continue to receive an error. I also receive an error when attempting to export customizations from the current CRM implementation. There appears to be a problem with one of my relationships (the error message on upgrade will follow). I am wondering if anyone can provide any hints or a series of SQL statements that might allow me to track down a fault relationship (or suggest another cause). Thank you

    System.Exception: Action Microsoft.Crm.Tools.Admin.UpgradeDatabaseAction failed. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
       at Microsoft.Crm.Metadata.PreloadedMetadataInitializationContext.GetEntityRelationshipProvider(Guid entityRelationshipId)
       at Microsoft.Crm.Metadata.PreloadedMetadataCacheDataProvider.AddEntityRelationshipRelationshipsToCollections(IPreloadedMetadataInitializationContext context)
       at Microsoft.Crm.Metadata.PreloadedMetadataCacheDataProvider.Initialize(IOrganizationContext organizationContext, MetadataContainer container, LoadMasks masks)
       at Microsoft.Crm.Metadata.DynamicMetadataCacheLoader.CreateMetadataCacheDataProvider(MetadataContainer container, IOrganizationContext context, LoadMasks masks, CounterList counter)
       at Microsoft.Crm.Metadata.DynamicMetadataCacheLoader.BuildMetadataCacheFromMetadataContainer(MetadataContainer container, LoadMasks masks, IOrganizationContext context, CounterList counter)
       at Microsoft.Crm.Metadata.DynamicMetadataCacheLoader.LoadCacheFromDatabaseInternal(LoadMasks masks, CrmDbConnection connection, CrmTransaction transaction, IOrganizationContext context, CounterList counter)
       at Microsoft.Crm.Metadata.DynamicMetadataCacheLoader.LoadCacheFromDatabase(LoadMasks masks, IOrganizationContext context, CounterList counter)
       at Microsoft.Crm.Metadata.DynamicMetadataCacheFactory.LoadMetadataCache(LoadMethod method, CacheType type, LoadMasks masks, IOrganizationContext context)
       at Microsoft.Crm.Setup.MetadataCacheLoadHelper.LoadCacheFromDatabase(CacheType existingMetadataCacheType, LoadMasks masks, String connectionString, Guid organizationId)
       at Microsoft.Crm.Setup.DiffBuilder.PopulateExistingMetadataCacheFromDatabase(CacheType existingMetadataCacheType, String connectionString)
       at Microsoft.Crm.Setup.DiffBuilder.Pass0(String metadataLocation)

    Thursday, October 20, 2011 9:05 PM

Answers

  • Hi,

    Just to let you know that MSFT has solved the problem. They imported our database and then did a full debug of the installation procedure. During this debug they encountered 2 things:

    • In a systemrelationship between quote and quotedetail the referencedentity field was set to "null", this was a corruption because the field should have contained data.
    • A saved user query had a corrupted value in a lookup field.

    They did send me 2 SQL scripts to address those issues and after executing them and import them again, the import worked successfully...

    Kind regards,

    Philippe


    it's all very nice when it works

    Thursday, May 31, 2012 12:34 PM

All replies

  • If you have any customizations such as plug-ins or javascript please remove all of it before attempting the upgrade.  Also ensure you have no unsupported changes on the database like triggers or functions.  Remove those as well before getting started.

    Regards, Donna

    Friday, October 28, 2011 12:56 PM
  • It would be a lot more helpfull if MSFT displayed what kind of key in what table...

    I've got the same type of error here but no clue to find where it fails


    it's all very nice when it works

    Thursday, March 8, 2012 6:06 PM
  • You can give Microsoft that feedback on Connect and have people vote for it.  I'll vote if you provide the link.

    http://connect.microsoft.com


    Regards, Donna

    Thursday, March 8, 2012 9:57 PM
  • Dear Donna E.,

    Thanks for the tip, I posted this on the connect form with this URL:

    https://connect.microsoft.com/dynamicssuggestions/feedback/details/731948/keynotfoundexception-on-upgrade-from-crm-4-0-to-2011

    I'm still trying to import but no luck, I'm afraid. This is the first upgrade from 4.0 to 2011 with more to come and let's say that I'm already a bit down when thinking on all future upgrades...

    Kind regards,


    it's all very nice when it works

    Monday, March 19, 2012 1:34 PM
  • Thank you for providing the link.  When it comes to upgrades, it is very important to take a very methodical approach.  The upgrade experience from CRM 4.0 to CRM 2011 is significantly improved.  Having said that, I understand that you are having challenges. 

    My best suggestion is to ensure you have removed all plug-ins and other customization that could be impacting your upgrade, remove any and all unsupported changes from the database, ensure that your infrastructure at least meets the minimum recommended settings (hardware and software) and follow the Import guide closely.  If you take this approach, you should have a successful import.  I know people that have done several hundred upgrades without issue following these guidelines.


    Regards, Donna

    Monday, March 19, 2012 4:01 PM
  • By the way, I just looked at your Connect post and I think you might have misunderstood my suggestion.  Connect is place for the community to share product suggestions or feature enhancement requests with Microsoft. 

    If you would like help for this specific issue and we are not able to point you in the right direction to resolve it here, then you will need to open a support case with Microsoft.  I hope this helps.


    Regards, Donna

    Monday, March 19, 2012 4:05 PM
  • Dear Donna,

    Before we started we examined the prerequisites carefully and always kept in mind when developing that we followed the rules for not breaking anything or doing unsupported customizations.

    With that, I check the plug-ins, there are only 2 of them in:

    • PluginInternal Operation, Microsoft.Crm.Extensibility.InternalOperationPlugin
    • V3CalloutProxyPlugin, Microsoft.Crm.Extensibility.V3CalloutProxyPlugin

    I think both of them are from MSFT itself.

    Afther that we removed everything what we could find from database unsupported functions and stored procedures that were added to our CRM system in version 3.0 by a partner organization to let there product work. We migrated in 2008 to crm 4.0, and ditched the 3party solution, however some stored procedures and function were still in the database.

    The machines are all meeting the minimum requirements, we updated the installation files when starting to foresee possible updates to them.

    The only thing where I cannot get information over is the language. Our CRM 4.0 is Dutch base language with english and french language packs. For harmony reasons, all our new infrastructure is english (and thus crm 2011 is also english base language). I read that it should be possible in this version to upgrade a base language to another base language when moving from 4.0 to 2011.

    Please advise if I'm wrong, if this is an issue we shall install CRM with the dutch base language and try this way.

    We had problems from 1.2 going to 3.0, 3.0 to 4.0 and now again to 2011. Everytime we called in MSFT support and after all it worked out but not a single support engineer could give us an explanation of why something had happened. They did create some SQL scripts to solve the issue and let the import process succeed, however it took them months to find the exact issue; it was always something to do with SQL Server.

    So we've had our share of import issues, and everytime a new version of CRM is released, we hear how great the import process now works, better then the previous version. But let's say that every time we'd start to begin an upgrade traject, we already know it will fail miserably. I also know al lot of people who upgrade CRM installation where is succeeds. After checking the contents of such installations, they are always the most simple CRM solutions.

    I think I will call MSFT support to handle this issue as it will probably be another unencountered issue never seen before.

    However, thanks for the suggestions. 


    it's all very nice when it works

    Wednesday, March 21, 2012 3:02 PM
  • I'll think we'll do this because I can't see any more thing I can do.

    Regards,

    Philippe


    it's all very nice when it works

    Wednesday, March 21, 2012 3:02 PM
  • Hi Phielippe,

    I had come across for same issue for one of our upgrade and it's been resolved as mentioned in following article..

    http://mayankp.wordpress.com/2012/03/21/crm-4-0-to-crm-2011-upgrade-issue-the-given-key-was-not-present-in-the-dictionary/

    Hope this helps..


    MayankP
    My Blog
    Follow Me on Twitter

    Wednesday, March 21, 2012 4:56 PM
    Answerer
  • Hey,

    Thanks for the suggestion!

    So we have to install a clean CRM 4.0, and then compare all the relations that are system relations (ignoring the ones from our own self created entities and relations) of our CRM 4.0 in the EntityRelationship table to the ones on a clean CRM 4.0 system. And then update the ones that have other configurations?

    Kind regards,

    Philippe


    it's all very nice when it works

    Wednesday, March 28, 2012 1:11 PM
  • Yes, it would be better if any developer/system customizor at your compnay remembering the changes done over entity relationship..this would save time becuase then you can just check these ones only..

    if they can't then you need to compare them with clean CRM 4.0 system..

    hope this helps..


    MayankP
    My Blog
    Follow Me on Twitter

    Wednesday, March 28, 2012 1:40 PM
    Answerer
  • Because it was an external company, I'll start looking myself...

    I'll keep you posted.


    it's all very nice when it works

    Monday, April 2, 2012 1:49 PM
  • Hi,

    With some help of Excel I compared all 1184 rows out of a CRM 4.0 with no customizations to our system. When first removing all our customizations and then comparing all values from the 3 columns (EntityRelationshipType, IsCustomRelationship,CustomizationLevel) with our values... all our values are the same as in the orginal.

    So this solution didn't work out...

    Any other ideas I can check?

    thanks


    it's all very nice when it works


    Monday, April 2, 2012 2:54 PM
  • Since you say you've removed all unsupported customization left over from the third party solution, have  you tried the upgrade after matching the language in 2011 with the language in 4?  I realize that you've heard that it is not necessary but, since the upgrade is not working, it might be worth trying. 

    Also, ensure that your CRM 4 application is on the latest Update Rollup and CRM 2011 is on the latest Update Rollup to rule out any Update Rollup issues.  I'll make the assumption that the 2011 is configured correctly since you said you've followed the prerequisite and other steps carefully.

    At what point in the import process is the failure occurring?  Have you opened and reviewed the log file for additional information?


    Regards, Donna


    Monday, April 2, 2012 3:50 PM
  • Hello,

    I was trying to figure out at what point the upgrade fails, but I cannot find a clue; this the extract from my log file.

    We have already running 4 organizations on our new CRM 2011 installation and everything works great. So I think the installation was a succes. We will definitely try to set up a new machine with base language dutch (as now it is english) and try to import again.

    If that is not working out, we'll call in the troops (MSFT) for assistance.

    18:59:18|Verbose| Updated 132 rows for Customer attribute for entity 'SalesOrder'
    18:59:18|Verbose| Updated 480 rows for Customer attribute for entity 'ContractDetail'
    18:59:18|Verbose| DatabaseAction execution time; Bin\Microsoft.Crm.DataUpgrade.dll:CreateAndPopulateCustomerIdTables; 00:00:01.1561982
    18:59:18|   Info| Refererende sleutels voor logische relaties verwijderen
    18:59:19|Verbose| DatabaseAction execution time; Bin\Microsoft.Crm.Setup.DiffBuilder.dll:DropForeignKeysForLogicalRelationships; 00:00:00.2968617
    18:59:19|   Info| Kenmerken transactievaluta en wisselkoers op aanpasbare entiteiten upgraden
    18:59:31|Verbose| DatabaseAction execution time; Bin\Microsoft.Crm.Setup.DiffBuilder.dll:UpgradeCustomTransactionCurrencyAndExchangeRateAttributesOnSystemEntities; 00:00:12.0463353
    18:59:31|   Info| Kenmerken transactievaluta en wisselkoers op aanpasbare entiteiten upgraden
    18:59:37|Verbose| DatabaseAction execution time; Bin\Microsoft.Crm.Setup.DiffBuilder.dll:UpgradeKBArticleTransactionCurrencyAndExchangeRateAttributesIfCustomizable; 00:00:06.4372116
    18:59:37|   Info| Id's voor weerlegbaarheidskenmerken opnieuw instellen
    18:59:41|Verbose| DatabaseAction execution time; Bin\Microsoft.Crm.Setup.DiffBuilder.dll:ResetIdsForRepudiationAttributes; 00:00:03.9841965
    18:59:41|   Info|
            Naam van tabel ActivityMimeAttachment wijzigen
         
    18:59:41|Verbose| Find if the Attachment table already exists
    18:59:41|Verbose| Attachment table does not exist.
    18:59:41|Verbose| Dropping all indexes except primary key index on ActivityMimeAttachment
    18:59:41|Verbose| Dropping all constraints on ActivityMimeAttachment
    18:59:42|Verbose| Renaming ActivityMimeAttachment table to ActivityMimeAttachment_{6340de00-f1f4-4dc1-9aab-a202e8566390}
    18:59:42|Verbose| DatabaseAction execution time; Bin\Microsoft.Crm.DataUpgrade.dll:RenameAndRecreateAmaTable; 00:00:00.8749608
    18:59:42|   Info| DiffBuilder: fase 0
    18:59:46|   Info| CrmAction execution time; UpgradeDatabaseAction; 00:01:58.2295802
    18:59:46|  Error| Installer Complete: OrganizationUpgrader - Error encountered
    18:59:46|  Error| Exception occured during Microsoft.Crm.Tools.Admin.OrganizationUpgrader: Action Microsoft.Crm.Tools.Admin.UpgradeDatabaseAction failed.
    InnerException:
    System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
       at Microsoft.Crm.Metadata.PreloadedMetadataInitializationContext.GetEntityProvider(Guid entityId)
       at Microsoft.Crm.Metadata.PreloadedMetadataCacheDataProvider.AddRelationshipsToCollections(IPreloadedMetadataInitializationContext context)
       at Microsoft.Crm.Metadata.PreloadedMetadataCacheDataProvider.Initialize(IOrganizationContext organizationContext, MetadataContainer container, LoadMasks masks)
       at Microsoft.Crm.Metadata.DynamicMetadataCacheLoader.CreateMetadataCacheDataProvider(MetadataContainer container, IOrganizationContext context, LoadMasks masks, CounterList counter)
       at Microsoft.Crm.Metadata.DynamicMetadataCacheLoader.BuildMetadataCacheFromMetadataContainer(MetadataContainer container, LoadMasks masks, IOrganizationContext context, CounterList counter)
       at Microsoft.Crm.Metadata.DynamicMetadataCacheLoader.LoadCacheFromDatabaseInternal(LoadMasks masks, CrmDbConnection connection, CrmTransaction transaction, IOrganizationContext context, CounterList counter)
       at Microsoft.Crm.Metadata.DynamicMetadataCacheLoader.LoadCacheFromDatabase(LoadMasks masks, IOrganizationContext context, CounterList counter)
       at Microsoft.Crm.Metadata.DynamicMetadataCacheFactory.LoadMetadataCache(LoadMethod method, CacheType type, LoadMasks masks, IOrganizationContext context)
       at Microsoft.Crm.Setup.MetadataCacheLoadHelper.LoadCacheFromDatabase(CacheType existingMetadataCacheType, LoadMasks masks, String connectionString, Guid organizationId)
       at Microsoft.Crm.Setup.DiffBuilder.PopulateExistingMetadataCacheFromDatabase(CacheType existingMetadataCacheType, String connectionString)
       at Microsoft.Crm.Setup.DiffBuilder.Pass0(String metadataLocation)
       --- End of inner exception stack trace ---


    it's all very nice when it works

    Monday, April 2, 2012 4:49 PM
  • Hi,

    Just to let you know that MSFT has solved the problem. They imported our database and then did a full debug of the installation procedure. During this debug they encountered 2 things:

    • In a systemrelationship between quote and quotedetail the referencedentity field was set to "null", this was a corruption because the field should have contained data.
    • A saved user query had a corrupted value in a lookup field.

    They did send me 2 SQL scripts to address those issues and after executing them and import them again, the import worked successfully...

    Kind regards,

    Philippe


    it's all very nice when it works

    Thursday, May 31, 2012 12:34 PM