gpt4 book ai didi

c# - SaveChanges CRM 2011 插件上未处理的异常

转载 作者:行者123 更新时间:2023-12-02 05:11:48 25 4
gpt4 key购买 nike

我的 CRM 2011 插件有问题。

var QuoteProduct = crm.QuoteDetailSet.Where(c 
=> c.QuoteDetailId == QPID).First();
double Tax = (double)(
(QuoteProduct.BaseAmount
- QuoteProduct.ManualDiscountAmount.GetValueOrDefault()
- QuoteProduct.VolumeDiscountAmount.GetValueOrDefault()) / 20);
QuoteProduct.Attributes["tax"] = Tax;
crm.UpdateObject(QuoteProduct);
crm.SaveChanges();

错误发生在保存更改行。错误详情如下。

Microsoft.Xrm.Sdk.SaveChangesException was unhandled by user code
Message=An error occured while processing this request.
Source=Microsoft.Xrm.Sdk
StackTrace:
at Microsoft.Xrm.Sdk.Client.OrganizationServiceContext.SaveChanges(SaveChangesOptions options)
at Plugin.TaxCreator(IOrganizationService service, Guid QPID) in C:\Users\mycrm\Desktop\BMSD.QuoteProduct.Tax\BMSD.QuoteProduct.Tax\BMSD.QuoteProduct.Tax.cs:line 62
at Plugin.Execute(IServiceProvider serviceProvider) in C:\Users\mycrm\Desktop\BMSD.QuoteProduct.Tax\BMSD.QuoteProduct.Tax\BMSD.QuoteProduct.Tax.cs:line 38
at Microsoft.Crm.Extensibility.V5PluginProxyStep.ExecuteInternal(PipelineExecutionContext context)
at Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.Execute(PipelineExecutionContext context)
InnerException: System.ServiceModel.FaultException Message=System.InvalidCastException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #BE061894
Source=Microsoft.Crm.Extensibility
StackTrace:
at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.Execute(OrganizationRequest request, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType)
at Microsoft.Crm.Extensibility.InprocessServiceProxy.ExecuteCore(OrganizationRequest request)
at Microsoft.Xrm.Sdk.Client.OrganizationServiceContext.Execute(OrganizationRequest request)
at Microsoft.Xrm.Sdk.Client.OrganizationServiceContext.SaveChange(OrganizationRequest request, IList`1 results)
InnerException:

最佳答案

从您的堆栈跟踪中有一个 System.InvalidCastException

这意味着某些属性的值类型不正确。由于您仅更改“税”属性,因此其类型不正确。 "tax"很可能是一个 Money 字段,所以我猜你应该为它分配 decimal 类型的变量,而不是 double。尝试这样的事情:

decimal Tax = (decimal)((QuoteProduct.BaseAmount 
- QuoteProduct.ManualDiscountAmount.GetValueOrDefault()
- QuoteProduct.VolumeDiscountAmount.GetValueOrDefault()) / 20);

关于c# - SaveChanges CRM 2011 插件上未处理的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15320363/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com