I registered a plugin for our product quotes. The plugin worked well in our test environment. I have tested this many times. Then registered the plugin on the main server. However, the following scenario occurs: When I create or update a quotation product, the product form is first issued with a quote:

After I click on the quotation mark form, an error appears. Log files are not available (as you see). I debugged the plugin, but there is no error either. After I click OK, the error will disappear and the required business will occur in the product quotes (for the tax field). It means that the plugin code has no errors and does its job well. The code looks like this:
using System; using System.Diagnostics; using System.Linq; using System.ServiceModel; using Microsoft.Xrm.Sdk; using Xrm; using System.Collections.Generic; using Microsoft.Xrm.Sdk.Deployment; public class Plugin : IPlugin { public void Execute(IServiceProvider serviceProvider) { IPluginExecutionContext context = (IPluginExecutionContext) serviceProvider.GetService(typeof(IPluginExecutionContext)); Entity entity; if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity) { entity = (Entity)context.InputParameters["Target"]; if (entity.LogicalName != "quotedetail") { return; } } else { return; } try { IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService( typeof(IOrganizationServiceFactory)); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); if (context.MessageName == "Create") { Entity QuoteProduct = (Entity)context.InputParameters["Target"]; Guid QPID = QuoteProduct.Id; TaxCreator(service, QPID); } if (context.MessageName == "Update" && context.Depth < 3) { Entity QuoteProduct = (Entity)context.PostEntityImages["Target"]; Guid QPID = QuoteProduct.Id; TaxUpdater(service, QPID); } } catch (FaultException<OrganizationServiceFault> ex) { throw new InvalidPluginExecutionException( "An error occurred in the plug-in.", ex); } } private static void TaxCreator(IOrganizationService service, Guid QPID) { using (var crm = new XrmServiceContext(service)) { var QuoteProduct = crm.QuoteDetailSet.Where(c => c.QuoteDetailId == QPID).First(); var SaleSetting = crm.new_salessettingSet.Where(c => c.statecode == 0).First(); double TaxPercent = (Convert.ToDouble(SaleSetting.new_TaxPercent) / 100); if (QuoteProduct.IsPriceOverridden == false) { decimal Tax = (decimal)Convert.ToDecimal(Convert.ToDouble(QuoteProduct.BaseAmount - QuoteProduct.ManualDiscountAmount.GetValueOrDefault()) * TaxPercent); decimal PricePerUnit = (decimal)(QuoteProduct.PricePerUnit.GetValueOrDefault() - QuoteProduct.VolumeDiscountAmount.GetValueOrDefault()); crm.UpdateObject(QuoteProduct); crm.SaveChanges(); QuoteProduct.Attributes["tax"] = new Money(Tax); QuoteProduct.Attributes["new_result"] = new Money(PricePerUnit); crm.UpdateObject(QuoteProduct); crm.SaveChanges(); } } } private static void TaxUpdater(IOrganizationService service, Guid QPID) { using (var crm = new XrmServiceContext(service)) { var QuoteProduct = crm.QuoteDetailSet.Where(c => c.QuoteDetailId == QPID).First(); var SaleSetting = crm.new_salessettingSet.Where(c => c.statecode == 0).First(); double TaxPercent = (Convert.ToDouble(SaleSetting.new_TaxPercent) / 100); if (QuoteProduct.IsPriceOverridden == false) { decimal Tax = (decimal)Convert.ToDecimal(Convert.ToDouble(QuoteProduct.BaseAmount - QuoteProduct.ManualDiscountAmount.GetValueOrDefault()) * TaxPercent); decimal PricePerUnit = (decimal)(QuoteProduct.PricePerUnit.GetValueOrDefault() - QuoteProduct.VolumeDiscountAmount.GetValueOrDefault()); crm.UpdateObject(QuoteProduct); crm.SaveChanges(); QuoteProduct.Attributes["tax"] = new Money(Tax); QuoteProduct.Attributes["new_result"] = new Money(PricePerUnit); crm.UpdateObject(QuoteProduct); crm.SaveChanges(); } } } }
I also checked the server event viewer for errors, and no result! I registered my plugin to create and update product quotes. Any help is appreciated.
source share