2

我正在尝试从我的 C# 代码更新发票字段“freightamount”。我能够像字符串和 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.

这是我的代码的一部分:

我使用对“ Microsoft.Xrm.Sdk”的引用

然后在代码中:

 invoice.Attributes.Add(new KeyValuePair<string, object>("freightamount",  new Microsoft.Xrm.Sdk.Money (row.amount)));

哪里row.amount是十进制值。

4

1 回答 1

1

您是否尝试过将 Money 添加为 Entity 类的 KnownTypeAttribute,方法是将其添加到 web.config 中?

<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>
于 2014-06-24T14:20:56.963 回答