Hello,
My plugin after triggered three times in a row trigger the following error:
Unhandled exception:
Exception type: System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]
Message: Context is not initialized or already cleaned up.Detail:
<OrganizationServiceFault xmlns:i="www.w3.org/.../XMLSchema-instance" xmlns="schemas.microsoft.com/.../Contracts">
<ActivityId>6877745f-38c9-4398-aea8-9c8c8206d6e3</ActivityId>
<ErrorCode>-2147220970</ErrorCode>
<ErrorDetails xmlns:d2p1="schemas.datacontract.org/.../System.Collections.Generic" />
<Message>Context is not initialized or already cleaned up.</Message>
<Timestamp>2019-03-01T13:04:20.4270214Z</Timestamp>
<ExceptionRetriable>false</ExceptionRetriable>
<ExceptionSource i:nil="true" />
<InnerFault i:nil="true" />
<OriginalException i:nil="true" />
<TraceText>
[Dynamics365.Plugins: Dynamics365.OpportunityProduct.OpportunityProductPreUpdate]
[507fa119-173c-e911-a963-000d3a441525: Dynamics365.OpportunityProduct.OpportunityProductPreUpdate: Update of opportunityproduct]
Entered Microsoft.Dynamics.Sales.Plugins.PreOperationOpportunityLineUpdate.Execute(), Correlation Id: e8a14c5d-b906-45c9-ad5a-b8db80348a4e, Initiating User: f1bd823b-7739-4aad-8e76-42c7092e9dce
Exiting Microsoft.Dynamics.Sales.Plugins.PreOperationOpportunityLineUpdate.Execute(), Correlation Id: e8a14c5d-b906-45c9-ad5a-b8db80348a4e, Initiating User: f1bd823b-7739-4aad-8e76-42c7092e9dce
</TraceText>
</OrganizationServiceFault>
Here is my pluginbase class:
public abstract class PluginsBase : IPlugin
{
public IBusinessContext BusinessContext { get; set; }
public IOrganizationService OrganizationService { get; set; }
public IOrganizationServiceFactory OrganizationServiceFactory { get; set; }
public IPluginExecutionContext PluginExecutionContext { get; set; }
public ITracingService TracingService { get; set; }
public IDomainService DomainServices { get; set; }
public Entity Entity;
public Entity PreImage;
public string PreImageTarget = "Image";
public string Target = "Target";
public void Execute(IServiceProvider serviceProvider)
{
PluginExecutionContext = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
OrganizationServiceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
OrganizationService = OrganizationServiceFactory.CreateOrganizationService(PluginExecutionContext.UserId);
BusinessContext = new BusinessContext(serviceProvider);
TracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
DomainServices = new DomainService(BusinessContext, TracingService);
ExecutePlugin(serviceProvider);
}
public abstract void ExecutePlugin(IServiceProvider serviceProvider);
}
Thanks in advance.