While importing CRM 4.0 organization to CRM 2011 environment we were kept getting error and error log is recording error as mentioned below..
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 System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at Microsoft.Crm.Metadata.PreloadedMetadataCacheDataProvider.AddEntityRelationshipRolesToCollections(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 ---
at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at Microsoft.Crm.Setup.Database.DllMethodAction.Execute()
at Microsoft.Crm.Setup.Database.DatabaseInstaller.ExecuteReleases(ReleaseInfo releaseInfo, Boolean isInstall)
at Microsoft.Crm.Setup.Database.DatabaseInstaller.Install(Int32 languageCode, String configurationFilePath, Boolean upgradeDatabase, Boolean isInstall)
at Microsoft.Crm.Tools.Admin.InstallDatabaseAction.Do(IDictionary parameters)
at Microsoft.Crm.Setup.Common.CrmAction.ExecuteAction(CrmAction action, IDictionary parameters, Boolean undo)
InnerException:
System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at Microsoft.Crm.Metadata.PreloadedMetadataCacheDataProvider.AddEntityRelationshipRolesToCollections(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)
Solution
After investigating this issue further (and trying import multiple times) we guessed that issue is coming because CRM 4.0 organization had one of the unsupported customization applied on one of system entity relationship behaviour.
So first thing is to find out which entity relationship is causing this issue and once this is found then revert that changes in staging database (on top of fresh CRM 4.0 database before importing in to CRM 2011 as Organization).
We found this entity relationship and it is against “contact_as_responsible_contact” for this current Organization.
The way to find this out is compare your organization’s EntityRelationship table against standard out of the box CRM 4.0 EntityRelationship table.
After this we need to update problematic table records to match to system behaviour (CRM 4.0 out of box). We have run following script for the same.(please note schema name and ID would be different for your organization)
Update [MetadataSchema].[EntityRelationship]
set [IsCustomRelationship] =0,
[CustomizationLevel]=0
where SchemaName ='contact_as_responsible_contact'
Update [MetadataSchema].EntityRelationshipRelationships
set [CustomizationLevel] =0
where EntityRelationshipId ='ECE6333A-F356-42C5-BB26-B454DC0C0B33'
Update [MetadataSchema].EntityRelationshipRole
set [CustomizationLevel] =0
where EntityRelationshipId ='ECE6333A-F356-42C5-BB26-B454DC0C0B33'
Hope this helps..
Note: This is unsupported customization, Please unit test this module on your development/test environment before applying it to Live Environment…
Cheers,
MayankP:)
Hi Mayank,
I am also having the same kind of issue.
can you suggest me the way to find the Unsupported customization in relationships?
Thanks,
Ravikumar.
Hi Ravi,
if your error log comes with same stack trace then this could be due to Entity relationship behaviour..
so on your CRM 4.0 environment , create new organization let’s call it NEW which will create database called NEW_MSCRM
Now compare the table records for metadataschema.entityrelationship for system generated entity on NEW_MSCRM database and your CRM 4.0 Organization.
you can export record to excel then compare it or use any other tools to compare two data table records..
once you find problematic relationship then just run script to fix this.
hope this helps..