C# 尝试更新C中的货币字段时出错#
我正试图从我的C#代码中更新发票字段“freightamount”。我可以更新其他字段,如字符串和Guid,但为了钱,我在创建或更新发票实体时出现以下错误:C# 尝试更新C中的货币字段时出错#,c#,dynamics-crm-2011,currency,inner-exception,C#,Dynamics Crm 2011,Currency,Inner Exception,我正试图从我的C#代码中更新发票字段“freightamount”。我可以更新其他字段,如字符串和Guid,但为了钱,我在创建或更新发票实体时出现以下错误: There was an error while trying to serialize parameter http://schemas.microsoft.com/xrm/2011/Contracts/Services:entity. The InnerException message was 'Type 'Micr
There was an error while trying to serialize parameter
http://schemas.microsoft.com/xrm/2011/Contracts/Services:entity. The InnerException
message was 'Type 'Microsoft.Xrm.Sdk.Money' with data contract name
'Money:http://schemas.microsoft.com/xrm/2011/Contracts' is not expected. Consider using a
DataContractResolver or add any types not known statically to the list of known types -
for example, by using the KnownTypeAttribute attribute or by adding them to the list of
known types passed to DataContractSerializer.'. Please see InnerException for more
details.
这是我代码的一部分:
invoice.Attributes.Add(new KeyValuePair<string, object>("freightamount", new Microsoft.Xrm.Sdk.Money (row.amount)));
我使用了对“Microsoft.Xrm.Sdk
”的引用
然后在代码中:
invoice.Attributes.Add(new KeyValuePair<string, object>("freightamount", new Microsoft.Xrm.Sdk.Money (row.amount)));
invoice.Attributes.Add(新的KeyValuePair(“freightamount”,新的Microsoft.Xrm.Sdk.Money(row.amount));
其中,
行。金额
是一个十进制值 您是否尝试过通过将实体类添加到web.config来将金钱添加为实体类的KnownTypeAttribute
<system.runtime.serialization>
<dataContractSerializer>
<declaredTypes>
<add type="Microsoft.Xrm.Sdk.Entity, Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<knownType type = "Microsoft.Xrm.Sdk.Money, Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</add>
</declaredTypes>
</dataContractSerializer>
</system.runtime.serialization>
你能试试吗:发票[“运费金额”]=新钱(行金额)代码>我收到错误:“无法对MyProjectName.CRMServiceName.Entity类型的表达式应用索引”是否使用早期绑定的实体类型?如果是这样,您是否忘记对OrganizationServiceProxy对象调用EnableProxyTypes()?不,我使用的是LateBound。发票类型为“实体”。我可以更新除“货币”字段以外的任何字段。我必须创建一个类型为“Decimal”的新字段来添加发票金额。当您使用latebound进行选择时,金额的值类型是什么?我猜钱只用于earlybound,你应该输入小数点而不是钱。