locked
Microsoft.Crm.ObjectModel.MultiCurrencyPlugin + The given key was not present in the dictionary. RRS feed

  • Question

  • I am working with MS CRM 4.0. I have made a custom entity which is having some money fields. Everything was working fine. Suddenly while saving the entity below message coming from applicaton:
    "The given key was not present in the dictionary"
    If i click ok then entity is not saving. I go to application server event viewer log and saw below error details. Do any body face this issue, please let me know, it is getting me too much trouble. I know it is related with money field. I have to use money field in my entity. I have added some also.



    Web Service Plug-in failed in OrganizationId: cd39754d-37cd-49f9-80eb-d27ead74ae35; SdkMessageProcessingStepId: 58e202dd-4b49-417a-b732-f95957ef99b0; EntityName: new_distribution; Stage: 20; MessageName: Update; AssemblyName: Microsoft.Crm.ObjectModel.MultiCurrencyPlugin, Microsoft.Crm.ObjectModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35; ClassName: Microsoft.Crm.ObjectModel.MultiCurrencyPlugin; Exception: Unhandled Exception: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.

    at System.ThrowHelper.ThrowKeyNotFoundException()

    at System.Collections.Generic.Dictionary`2.get_Item(TKey key)

    at Microsoft.Crm.Sdk.PropertyBag.get_Item(String key)

    at Microsoft.Crm.ObjectModel.CaptureExchangeRate.FetchExchangeRate(Guid transactionCurrencyId, EntityMetadata entityMetadata, ExecutionContext context)

    at Microsoft.Crm.ObjectModel.CaptureExchangeRate.CaptureExchangeRateInternal(DynamicEntity entity, IBusinessEntity entityPreImage, EntityMetadata entityMetadata, String transactionCurrencyEntityName, String exchangeRateFieldName, String transactionCurrencyFieldName, ExecutionContext context, Boolean isCurrencyInPropBag, Boolean isCurrencyNullInPropBag, Boolean isCurrencyNullInPreImg, Boolean isMoneyFieldInPropBag, Boolean isCreateOperation, Boolean isSetStateOperation, ArrayList unchangedAttributes)

    at Microsoft.Crm.ObjectModel.CaptureExchangeRate.Execute(EntityDataInformation entityDataInformation)

    at Microsoft.Crm.ObjectModel.MultiCurrencyPlugin.Execute(IPluginExecutionContext context)

    at Microsoft.Crm.Extensibility.PluginStep.Execute(PipelineExecutionContext context)

    .

    For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

    Friday, October 16, 2009 11:08 AM

Answers

All replies

  • That error message drove me crazy for a few days.  It really means that the property you're trying to use has no data in the propertybag.  The property bag only has the minimun information required to create or change the record.  Blank fields on create and un-changed fields on updates aren't in there.  Depending on what you're trying to accomplish, you may need to register a pre-image or use the crm service to retrieve the data you're missing. 
    Friday, October 16, 2009 11:53 AM
  • Yes, I agree with Mike.  It's a nightmare.

     We had this suddenly pop up on the Lead entity and it "spread" to other entities, MS Help Desk sorted it via re-registering as Mike suggested. 
    Friday, October 16, 2009 4:11 PM
  • may you paste your code ?
    Saturday, October 17, 2009 12:55 AM
  • Hi Mike...
    I am not 100% getting your answer. Specially i did not get your last line. What did you mean by "you may need to register a pre-image or use the
    crm service to retrieve the data you're missing. "
    Will be please tell me in details how to perform the steps you want to mention. Thanks...
    Saturday, October 17, 2009 11:27 AM
  • My created entity is a totally customized entity. Could you please tell me how MS Help Desk helped you or could you please guide me how to reach them? Thanks...
    Saturday, October 17, 2009 11:29 AM
  • I do not understand which code you are talking about. Thanks...
    Saturday, October 17, 2009 11:30 AM
  • Hi,

    have you accidently removed the plugins which are registered by the system? See http://www.eggheadcafe.com/software/aspnet/31577428/plugin-registration-tool.aspx
    Have you deleted any currency_base fields or the exchange rate attribute? See http://support.microsoft.com/kb/954018
    Saturday, October 17, 2009 11:46 AM
  • I'll use my scenario to try and explain:

    We wanted to track a quote in an external application and created a custom entity in CRM to represent it.  One of the properties of the custom entity is a quote number.  The plugin makes a SQL call to get the cost, sell, profit and quote expiration date and populate these properties based on finding a match for the quote number.  As pricing may have changed or a different quote may have been created in the external application, we needed a way to update CRM.  The plugin was registered for the Create and Update messages.  Create worked fine.  On updates I would sometimes get the error you mentioned.  This occurred when a salesperson tried to updated the custome entity which had been created with a quote number that wasn't being changed so it wasn't being sent in the propertybag.  If the quote number was being changed, it would work.


     ExternalQuoteNumber = CustomEntity.Properties["cf_quotenumber"].ToString();  //  This is the line causing the error


     Using the plugin registration tool, I registered a preimage on the update message and selected the cf_quotenumber property to be in it.  I assigned this an alias name of PreImage.         

           // Process Update message
                    if (context.MessageName == MessageName.Update.ToString())
                    {
                        DynamicEntity PreImage = new DynamicEntity();
                            PreImage = (DynamicEntity)context.PreEntityImages["PreImage"];
                      
                       
                        try
                        {
                            if (CustomEntity.Properties.Contains("cf_quotenumber"))
                                ExternalQuoteNumber = CustomEntity.Properties["cf_quotenumber"].ToString();
                               
                            else
                            {
                                if (PreImage.Properties.Contains("cf_quotenumber"))
                                    ExternalQuoteNumber = PreImage.Properties["cf_quotenumber"].ToString();
                                                                
                            }

                            // For a plug-in running in the parent pipeline, use this statement.
                            ICrmService crmService = context.CreateCrmService(true);

                                
                         
    I hope this helps,

    Mike

    Saturday, October 17, 2009 12:06 PM
  • Hi Mike,

    the error message states that the exception doesn't happen in a custom plugin. It happens in 'Microsoft.Crm.ObjectModel.MultiCurrencyPlugin' which is a system plugin.
    Saturday, October 17, 2009 12:34 PM
  • My mistake.  I thought MultiCurrencyPlugin was an sdk sample that Abdullah was using and that the changes he's made to his custom entity may not have been reflected in the way the plug-in was(is) registered.

    Thanks,

    Mike

    Saturday, October 17, 2009 1:31 PM
  • Thanks so much cKeller, Mike and others for your time with my issue. I am glad you have tried to provide me a solution :) I have found my specific solution @ http://blogs.msdn.com/crmpt/archive/2009/09/28/guideline-para-recriar-os-internaloperation-plugin-steps.aspx Thanks to
    John Peter Smith for his nice article which solve my issue.

    You can see details of the solution of my issue below:


    From my experience with the CRM 4.0 checked more frequently than expected that many administrators CRM eliminated (on purpose or by mistake) the following Plugin Steps.

     

    This fact is reflected in the occurrence of various errors when setting up / update the entity's account. The way to correct this "oversight" (let us call it) is to edit the code of the tool Plugin Registration tool. To download this application use the following url: http://code.msdn.microsoft.com/crmplugin/Release/ProjectReleases.aspx?ReleaseId=2010 To this we must find the line 62 of file StepRegistrationForm.cs and comment on the block if () Else () By publishing this small section of code can then rerun the application and manually add the previously removed STEPS. The steps are as follows:

    PARENT

     

    CHILD

     

    After we re-create the steps to register them et Voila, ready to roll. Note that with the elimination of the block if else, the following error will not occur, because the field Plugin will list the Internal Operation.

     

    Then leave a step by step description of recreating these steps. Rebuilding

    Walkthrough:

    1. Locate the line 62 of file StepRegistrationForm.cs (StepRegistrationForm).

    You will see the following code (without the comments of course!)

    /*/Check whether system plugins should be added to the list
       if (step != null && org[step.AssemblyId][step.PluginId].IsSystemCrmEntity)
       {
        cmbPlugins.Enabled = false;
       }
       else if (plugin != null && plugin.IsSystemCrmEntity)
       {
        plugin = null;
       }*/
       
       //Add the plugins
       CrmPlugin selectPlugin = null;
       foreach (CrmPluginAssembly assembly in org.Assemblies.Values)
       {
        foreach (CrmPlugin pluginType in assembly.Plugins.Values)
        {
         if (pluginType.PluginType == CrmPluginType.Plugin)/* && pluginType.CustomizationLevel != 0)*/
         {
          if (plugin != null )/*&& plugin.PluginId == pluginType.PluginId)*/
          {
           selectPlugin = pluginType;
           cmbPlugins.Items.Add(pluginType);
          }
          else if (!pluginType.IsSystemCrmEntity)
          {
           cmbPlugins.Items.Add(pluginType);
          }
         }
        }
       }

     

     

    2. Make the changes suggested (commented code)

    3. Start RegistrationTool Plugin.
    4. Enter the Connection Information and click Connect.
    5. Enter the password and click OK.
    6. Select the organization that is receiving the error and then click Connect.
    7. Expand (Assembly) Microsoft.Crm.ObjectModel, InternalOperation, click Register, and then click Register ner step.
    8. Write RetrieveExchangeRate for the message.
    9. None for the primary entity and entity Secondary to None.

    9.1 on plugin select the Internal Operation.
    10. Type "ObjectModel Implementation" for the description.
    11. Type 0 for the execution of the order.
    12. Select Pre state, Synchronous, Server and offline, and then click Parent Pipeline.
    13. Copy the following text to the configuration Unsecure:

     

    <MethodInfo> <MethodName> RetrieveExchangeRate </ MethodName> <DeclaringType> Microsoft.Crm.ObjectModel.TransactionCurrencyService, Microsoft.Crm.ObjectModel </ DeclaringType> <InputMappings> <INPUT> <Name> TransactionCurrencyId </ Name> </ input> < Input> <Name> ExecutionContext () </ Name> </ input> </ InputMappings> <OutputMappings> <Field> <Name> ExchangeRate </ Name> <Value> return-value </ Value> <ClrFormatter> System.Decimal </ ClrFormatter> </ Field> </ OutputMappings> </ MethodInfo>

    14. Click Update.
    15. Click InternalOperation click Register, and then click again Register New Step.
    17. Complete steps 8-14 again, but this time to Child Pipeline in step 12, instead of Father Pipeline

     

    I hope this article is to your liking.

    Abdullah al Rashed

    CRM Consultant.

    Tuesday, October 20, 2009 9:35 AM
  • Excellent!  I'm so glad you were able to find the answer.

    Mike
    Tuesday, October 20, 2009 6:39 PM
  • Thanks mike :)
    New problem arise...please see below and provide me a solution if you can...

    While saving the entity below message is poping:
    Exception has been thrown by the target of an invocation.

    If i go to CRM Server Application Event Viewer then below error details found:

    Web Service Plug-in failed in OrganizationId: cd39754d-37cd-49f9-80eb-d27ead74ae35; SdkMessageProcessingStepId: 58e202dd-4b49-417a-b732-f95957ef99b0;
    EntityName: new_distribution; Stage: 20; MessageName: Update; AssemblyName: Microsoft.Crm.ObjectModel.MultiCurrencyPlugin, Microsoft.Crm.ObjectModel,
    Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35; ClassName: Microsoft.Crm.ObjectModel.MultiCurrencyPlugin;
    Exception: Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
       at System.RuntimeMethodHandle._InvokeConstructor(Object[] args, SignatureStruct& signature, IntPtr declaringType)
       at System.RuntimeMethodHandle.InvokeConstructor(Object[] args, SignatureStruct signature, RuntimeTypeHandle declaringType)
       at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
       at Microsoft.Crm.Extensibility.PluginStep..ctor(Guid stepId, StepDescriptionCache stepDescriptionCache, SecureConfigurationCache stepSecureConfigurationCache, StepImageDescriptionCache stepImageDescriptionCache, CrmEventLog eventLog, IOrganizationContext context)
       at Microsoft.Crm.Extensibility.PipelineStepFactory.CreateInstance(Guid stepId, IOrganizationContext context)
       at Microsoft.Crm.Caching.PipelineStepCacheLoader.LoadCacheData(Guid key, ExecutionContext context)
       at Microsoft.Crm.Caching.ObjectModelCacheLoader`2.LoadCacheData(TKey key, IOrganizationContext context)
       at Microsoft.Crm.Caching.CrmMultiOrgCache`2.CreateEntry(TKey key, IOrganizationContext context)
       at Microsoft.Crm.Caching.CrmSharedMultiOrgCache`2.LookupEntry(TKey key, IOrganizationContext context)
       at Microsoft.Crm.Extensibility.ImageRetrievalStep.MergeEntityRequests(PipelineExecutionContext context, Dictionary`2 entityRequests)
       at Microsoft.Crm.Extensibility.ImageRetrievalStep.Execute(PipelineExecutionContext context)
       at Microsoft.Crm.Extensibility.Pipeline.Execute(PipelineExecutionContext context)
       at Microsoft.Crm.Extensibility.MessageProcessor.Execute(PipelineExecutionContext context)
       at Microsoft.Crm.Extensibility.InternalMessageDispatcher.Execute(PipelineExecutionContext context)
       at Microsoft.Crm.ObjectModel.CaptureExchangeRate.FetchExchangeRate(Guid transactionCurrencyId, EntityMetadata entityMetadata, ExecutionContext context)
       at Microsoft.Crm.ObjectModel.CaptureExchangeRate.CaptureExchangeRateInternal(DynamicEntity entity, IBusinessEntity entityPreImage, EntityMetadata entityMetadata, String transactionCurrencyEntityName, String exchangeRateFieldName, String transactionCurrencyFieldName, ExecutionContext context, Boolean isCurrencyInPropBag, Boolean isCurrencyNullInPropBag, Boolean isCurrencyNullInPreImg, Boolean isMoneyFieldInPropBag, Boolean isCreateOperation, Boolean isSetStateOperation, ArrayList unchangedAttributes)
       at Microsoft.Crm.ObjectModel.CaptureExchangeRate.Execute(EntityDataInformation entityDataInformation)
       at Microsoft.Crm.ObjectModel.MultiCurrencyPlugin.Execute(IPluginExecutionContext context)
       at Microsoft.Crm.Extensibility.PluginStep.Execute(PipelineExecutionContext context)
    Inner Exception: System.Xml.XmlException: Name cannot begin with the ' ' character, hexadecimal value 0x20. Line 1, position 50.
       at System.Xml.XmlTextReaderImpl.Throw(Exception e)
       at System.Xml.XmlTextReaderImpl.Throw(String res, String[] args)
       at System.Xml.XmlTextReaderImpl.Throw(Int32 pos, String res, String[] args)
       at System.Xml.XmlTextReaderImpl.ParseQName(Boolean isQName, Int32 startOffset, Int32& colonPos)
       at System.Xml.XmlTextReaderImpl.ThrowTagMismatch(NodeData startTag)
       at System.Xml.XmlTextReaderImpl.ParseEndElement()
       at System.Xml.XmlTextReaderImpl.ParseElementContent()
       at System.Xml.XmlTextReaderImpl.Read()
       at System.Xml.XmlLoader.LoadNode(Boolean skipOverWhitespace)
       at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc)
       at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
       at System.Xml.XmlDocument.Load(XmlReader reader)
       at Microsoft.Crm.SharedUtil.CreateXmlDocument(XmlTextReader reader)
       at Microsoft.Crm.SharedUtil.CreateXmlDocument(String xml)
       at Microsoft.Crm.Extensibility.InternalOperationPlugin..ctor(StepDescription stepDescription, IOrganizationContext context)
    .

    For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

    Friday, October 30, 2009 9:43 AM
  • Problem

    You may have problem like below :

     

    Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: An unexpected error occurred.Detail:
    <OrganizationServiceFault xmlns:i='http://www.w3.org/2001/XMLSchema-instance' xmlns='http://schemas.microsoft.com/xrm/2011/Contracts'>
      <ErrorCode>-2147220970</ErrorCode>
      <ErrorDetails xmlns:d2p1='http://schemas.datacontract.org/2004/07/System.Collections.Generic'>
        <KeyValuePairOfstringanyType>
          <d2p1:key>CallStack</d2p1:key>
          <d2p1:value xmlns:d4p1='http://www.w3.org/2001/XMLSchema' i:type='d4p1:string'>  
    at Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.Execute(PipelineExecutionContext context)
       at Microsoft.Crm.Extensibility.Pipeline.Execute(PipelineExecutionContext context)
       at Microsoft.Crm.Extensibility.MessageProcessor.Execute(PipelineExecutionContext context)
       at Microsoft.Crm.Extensibility.InternalMessageDispatcher.Execute(PipelineExecutionContext context)
       at Microsoft.Crm.Extensibility.ExternalMessageDispatcher.ExecuteInternal(IInProcessOrganizationServiceFactory serviceFactory, IPlatformMessageDispatcherFactory dispatcherFactory, String messageName, String requestName, Int32 primaryObjectTypeCode, Int32 secondaryObjectTypeCode, ParameterCollection fields, CorrelationToken correlationToken, CallerOriginToken originToken, UserAuth userAuth, Guid callerId, Guid transactionContextId, Int32 invocationSource, Nullable`1 requestId, Version endpointVersion)
       at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.ExecuteRequest(OrganizationRequest request, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType)
       at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.Execute(OrganizationRequest request, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType)</d2p1:value>
        </KeyValuePairOfstringanyType>
      </ErrorDetails>
      <Message>An unexpected error occurred.</Message>
      <Timestamp>2011-12-26T14:14:52.626077Z</Timestamp>
      <InnerFault i:nil='true' />
      <TraceText>

     

    [Microsoft.Crm.ObjectModel: Microsoft.Crm.ObjectModel.MultiCurrencyPlugin]
    [f6d4ebbb-0075-407d-8208-26575bfa39af: MultiCurrencyPlugin]

     


    </TraceText>
    </OrganizationServiceFault>

    Solution

    In Plugin Registration Tool if plugins in Microsoft.Crm.Extensibility.InternalOperation are disabled, enable then.

     

    Then the error should disappear.


    Seyfullah
    Tuesday, December 27, 2011 8:32 AM