Tuesday, April 16, 2019

Couldn’t complete execution of the plug-in within the 2-minute limit


Exception :
Unhandled exception:
Exception type: System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]
Message: An unexpected error occurred from ISV code. (ErrorType = ClientError) Unexpected exception from plug-in (Execute):  Plugins.InvoiceRowDiscountPostUpdate: System.TimeoutException: Couldn’t complete execution of the Plugins.InvoiceRowDiscountPostUpdate plug-in within the 2-minute limit.Detail:
  11660026-7fc6-4ee7-b43b-298d416013b9
  -2147220956
 
Business Requirement

When a discount of parent record gets updated, its need to
  1. Recalculate various tax amount and to update all associated child records.
  2. Update parent records itself with sum of calculated amount.



Root Cause Identified

We have Dynamics CRM Online SYNCHRONOUS plugin that was going on an infinite recursion when updating itself.

Solution
  1. We should remove all the attributes that are consider as filtering attribute in triggering the plugin from the entity before we trigger orgproxy.update

In my case, I had an attribute – new_discount

// Remove the discount attribute from the Parent Invoice Row to stop going in the infinite loop.
if (parentInvoiceRow.Contains("new_discount"))
   parentInvoiceRow.Attributes.Remove("new_discount");

    2) The update cannot be a part of ExecuteMultiple, even if you remove the triggering attribute. Below is self explanatory code 

UpdateRequest createRequest = new UpdateRequest { Target = singleChildInvoicerow };
requestWithResults.Requests.Add(createRequest);

// Cannot be a part of Request Multiple - going on an infinite Loop.
// UpdateRequest parentCreateRequest = new UpdateRequest { Target = parentInvoiceRow };
// requestWithResults.Requests.Add(parentCreateRequest);

// Execute all the requests in the request collection using a single web method call - for only Child Record.
ExecuteMultipleResponse responseWithResults = (ExecuteMultipleResponse)neoService.Execute(requestWithResults);

// Do a separate update for the parent record.
neoService.Update(parentInvoiceRow);

Plugin Registration Tool - Object reference not set to an instance of an object


Exception Details
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Xrm.Tooling.CrmConnectControl.CrmConnectionManager.SetConfigKeyInformation(Dictionary`2 configKeys)
   at Microsoft.Xrm.Tooling.CrmConnectControl.CrmServerLoginControl.StartConnectCheck()
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.Controls.Primitives.ButtonBase.OnClick()
   at System.Windows.Controls.Button.OnClick()
   at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)


Steps by Step Approach to get Plugin Registration working.

Step 1) Download the latest SKD (https://xrm.tools/SDK), before you try other method to get things correct for you.

Step 2) Try Clean the content of the folder - C:\Users\Username\AppData\Roaming\Microsoft\PluginRegistration


The Folder contains Previous connections made.

Step 3) Clean any content from the folder - C:\Users\Vipin\LiveDeviceID



After cleaning the content of the folder, I was not getting any exception but then Plugin Registration Tool repeatedly asking me to choose the organization and I was got stuck in a loop.

So, I decided to have the latest SDK from - https://xrm.tools/SDK and then everything started working well. Its weird though, Tool should have complain about the version problem at the very first stage.


Here are some other links for Troubleshooting and learning:

·       Plugin in Dynamic 365 CRM

·       Connect to Dynamic 365 CRM from Console App using Azure Authentication

·       Could not load file or assembly 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies

·       Unable to Login to Dynamics CRMOrganizationWebProxyClient is null

·       Assembly 'Microsoft.Crm.Sdk.Proxy' with identity 'Microsoft.Crm.Sdk.Proxy, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' uses 'Microsoft.Xrm.Sdk, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' which has a higher version than referenced assembly 'Microsoft.Xrm.Sdk' with identity 'Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

·       Could not load file or assembly 'Microsoft.Xrm.Sdk, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference.

·       Could not load file or assembly 'Microsoft.Xrm.Sdk, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies