Question

We're trying to update CRM 2011 from RU 11 to RU 14 to be able to install RU 15 when RU 14 is all ready to go. Been fixing various issues concerning this update since Microsoft did quite some changes due to the Cross Platform and obviously since were moving from the 11 to the 14.

Now, my main issue is that I have a plugin that's running synchronously on the create of a service appointment. It's in charge of doing several things, like comparing values or using values from other entities to populate data in the Service Activity record. Regarding what the strange error is, since changes are being done on a Post Operations, a _service.Update(entity) has to be done in order for changes to be seen in the form and database. If I debug the code step by step everything passes smoothly except when the code reaches the .Update. When the update is called CRM throws an Unexpected Error Occured. When I go to the TraceLogs this is what I find:


[2013-12-10 14:49:56.323] Process: w3wp |Organization:3e484d20-6245-e311-8a60-00155d6f6b34 |Thread:   20 |Category: Platform.Sdk |User: 0a51b463-df74-e011-81b3-00155d7a7a17 |Level: Error |ReqId: dca72532-8bed-491c-9295-62211d39a6f6 | VersionedPluginProxyStepBase.Execute  ilOffset = 0x65

at VersionedPluginProxyStepBase.Execute(PipelineExecutionContext context)  ilOffset = 0x65
at Pipeline.Execute(PipelineExecutionContext context)  ilOffset = 0x65
at MessageProcessor.Execute(PipelineExecutionContext context)  ilOffset = 0x1C5
at InternalMessageDispatcher.Execute(PipelineExecutionContext context)  ilOffset = 0xE4
at 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)  ilOffset = 0x156
at OrganizationSdkServiceInternal.ExecuteRequest(OrganizationRequest request, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType, UserAuth userAuth, Guid targetUserId, Boolean traceRequest, OrganizationContext context, Boolean returnResponse)  ilOffset = 0x145
at OrganizationSdkServiceInternal.ExecuteRequest(OrganizationRequest request, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType)  ilOffset = 0x34
at OrganizationSdkServiceInternal.Execute(OrganizationRequest request, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType)  ilOffset = 0x24
at InprocessServiceProxy.ExecuteCore(OrganizationRequest request)  ilOffset = 0x34
at SandboxSdkListener.Execute(SandboxCallInfo callInfo, SandboxSdkContext requestContext, String operation, Byte[] serializedRequest)  ilOffset = 0xAC
at   ilOffset = 0xFFFFFFFF
at SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)  ilOffset = 0x241
at DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)  ilOffset = 0x100
at ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)  ilOffset = 0x48
at ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)  ilOffset = 0xC6
at MessageRpc.Process(Boolean isOperationContextSet)  ilOffset = 0x62
at ChannelHandler.DispatchAndReleasePump(RequestContext request, Boolean cleanThread, OperationContext currentOperationContext)  ilOffset = 0x256
at ChannelHandler.HandleRequest(RequestContext request, OperationContext currentOperationContext)  ilOffset = 0xF1
at ChannelHandler.AsyncMessagePump(IAsyncResult result)  ilOffset = 0x39
at AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)  ilOffset = 0x0
at AsyncResult.Complete(Boolean completedSynchronously)  ilOffset = 0xC2
at TryReceiveAsyncResult.OnReceive(IAsyncResult result)  ilOffset = 0x4B
at AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)  ilOffset = 0x0
at AsyncResult.Complete(Boolean completedSynchronously)  ilOffset = 0xC2
at ReceiveAsyncResult.OnReceiveComplete(Object state)  ilOffset = 0x2B
at SessionConnectionReader.OnAsyncReadComplete(Object state)  ilOffset = 0xBC
at AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)  ilOffset = 0x0
at LazyAsyncResult.Complete(IntPtr userToken)  ilOffset = 0x3E
at NegotiateStream.ProcessFrameBody(Int32 readBytes, Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)  ilOffset = 0x70
at NegotiateStream.ReadCallback(AsyncProtocolRequest asyncRequest)  ilOffset = 0x68
at FixedSizeReader.CheckCompletionBeforeNextRead(Int32 bytes)  ilOffset = 0x5D
at FixedSizeReader.ReadCallback(IAsyncResult transportResult)  ilOffset = 0x29
at AsyncResult.Complete(Boolean completedSynchronously)  ilOffset = 0xC2
at IOAsyncResult.OnAsyncIOComplete(Object state)  ilOffset = 0x26
at SocketConnection.OnReceiveAsync(Object sender, SocketAsyncEventArgs eventArgs)  ilOffset = 0x57
at SocketAsyncEventArgs.FinishOperationSuccess(SocketError socketError, Int32 bytesTransferred, SocketFlags flags)  ilOffset = 0x5CB
at SocketAsyncEventArgs.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)  ilOffset = 0x10
at _IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)  ilOffset = 0x3C

>Web Service Plug-in failed in SdkMessageProcessingStepId: {B9CDBB1B-EA3E-DB11-86A7-000A3A5473E8}; EntityName: serviceappointment; Stage: 30; MessageName: Update; AssemblyName: Microsoft.Crm.Extensibility.InternalOperationPlugin, Microsoft.Crm.ObjectModel, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35; ClassName: **Microsoft.Crm.Extensibility.InternalOperationPlugin; Exception: Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.**
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Web.Services.Protocols.LogicalMethodInfo.Invoke(Object target, Object[] values)
at Microsoft.Crm.Extensibility.InternalOperationPlugin.Execute(IServiceProvider serviceProvider)
at Microsoft.Crm.Extensibility.V5PluginProxyStep.ExecuteInternal(PipelineExecutionContext context)
at Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.Execute(PipelineExecutionContext context)
**Inner Exception: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.**
Parameter name: index
at System.Collections.CollectionBase.System.Collections.IList.get_Item(Int32 index)
at Microsoft.Crm.BusinessEntities.BusinessEntityCollection.get_Item(Int32 index)
at Microsoft.Crm.ObjectModel.CommunicationActivityServiceBase.UpdateCommunicationPartiesInternal(BusinessEntityMoniker moniker, CommunicationActivity activity, ExecutionContext context, ExtensionEventArgs e)
at Microsoft.Crm.ObjectModel.CommunicationActivityServiceBase.UpdateCommunicationParties(Object sender, ExtensionEventArgs e)
at Microsoft.Crm.BusinessEntities.BusinessProcessObject.PostUpdateEventHandler.Invoke(Object sender, ExtensionEventArgs e)
at Microsoft.Crm.ObjectModel.GenericActivityServiceBase.UpdateInternal(IBusinessEntity entityInterface, ExecutionContext context)
at Microsoft.Crm.ObjectModel.CommunicationActivityServiceBase.Update(IBusinessEntity entityInterface, ExecutionContext context)
_______________

I've done different changes trying to figure out what the problem would be, among them, turning off all registered plugins other than Microsoft ones and this one. Turned off all JavaScript in the form in case any values are being changed that are making it throw the error, hard coded State Code and Status Code because of some related issues found online, commented ALL the code in the plugin and only left the _service.Update(entity) in case an invalid value was being passed but update would still throw error, and other things I found online that seemed like a solution. I've been going on this error for some time now and would like to have some more minds thinking this out with me. The plugin has to be run Synchronously and in the Post Operation because of logic tied to the plugin.

Any help is appreciated and if you need any more information to understand what could be going on please let me know.

Was it helpful?

Solution

I've been tearing my hair out of the exact same issue. My same code works fine on other types of entities, so I isolated it only occurring on a activities (i.e. anything that uses ActivityBase). This looks like a bug within CRM's internal object model (present at least in UR11, which is the version I'm running) that occurs in the following circumstance:

  • You're triggering a plugin that is:
    • against is an Activity (Appointment, Service Activity, Task, Email, etc) or custom Activity Type
    • Triggered on the Create message
    • Run Synchronously
    • Runs Post-Operation

One of the features that all Activity entities have compared to other entities that is the presence of activity participants (ActivityParties), which are standard fields like 'Attendees', 'Customers', useful email fields ('To', 'CC', 'BCC'), which can contain a number of different types such as 'RequiredAttendee', 'Organizer', 'To', but also importantly it creates one for the record 'Owner' too (see http://msdn.microsoft.com/en-us/library/gg328549.aspx for the full list).

After looking at the SQL that's being executed (and also a sneaky peek in a .NET decompiler within Microsoft.Crm.ObjectModel) it appears that the issue lies with the order in which the Activity Parties are (or aren't) being created or updated. For activities after the usual Create() message processing (including your plugin code) is finished executing, these ActivityParty record(s) (including one for the Owner) are populated from the entity data. On Update() there is also a check that processes any changes required to the ActivityParties, however this (erroneously) assumes that ActivityParty records have already been created.

..so if you're calling Update within the Create message, then the initial Create message hasn't finished before the Update ActivityParty throws it's ArgumentOutOfRangeException as it doesn't have any records yet.

This also explains why it works as expected in Async mode, as the ActivityParties are created successfully right after the usual Create() process but before the Update triggered by the plugin execution code runs a few seconds later.

Depending upon what you're trying to achieve, as a work around it might be possible to rework your plugin to function on the Pre-Operation event instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top