[英]Error when trying to update a Currency field in C#
I'm trying to update the invoice field "freightamount" from my C# code. 我正在尝试从C#代码更新发票字段“ freightamount”。 I'm able to update other fields well like strings and Guid but for Money I get this error on creating or updating the invoice entity: 我能够更新其他字段,例如字符串和Guid,但对于Money,在创建或更新发票实体时出现此错误:
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.
Here's a part of my code: 这是我的代码的一部分:
I use the reference to " Microsoft.Xrm.Sdk
" 我使用对“ Microsoft.Xrm.Sdk
”的引用
Then in code: 然后在代码中:
invoice.Attributes.Add(new KeyValuePair<string, object>("freightamount", new Microsoft.Xrm.Sdk.Money (row.amount)));
Where row.amount
is a decimal value. 其中row.amount
是一个十进制值。
Have you tried adding Money as a KnownTypeAttribute for the Entity class by adding it to the web.config? 您是否尝试过通过将Money添加到web.config来将钱添加为Entity类的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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.