简体   繁体   English

尝试更新C#中的“货币”字段时出错

[英]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.

相关问题 Unity C#:尝试在Update()中调用类的函数时出错 - Unity C#: Error when trying to call a class' functions in Update() 为什么我在尝试进行货币计算时会收到错误的输入字符串错误? C# - Why am I getting an incorrect input string error when I am trying to make currency calculations? C# C#-尝试使用datagridview(也使用OleDbCommandBuilder)更新访问数据库时出现“更新语句中的语法错误” - C# - “Syntax error in update statement” when trying to update the access database using datagridview (also using OleDbCommandBuilder) 尝试从C ++ / CLI访问C#程序集中的公共const字段时编译器错误 - Compiler error when trying to access public const field in C# assembly from C++/CLI 尝试更新ASP.NET(C#)gridview日期时间字段 - Trying to update a ASP.NET(C#) gridview datetime field 添加新字段(C#)后尝试查询Mongodb数据库时出错 - Error when trying to query Mongodb database after adding new field (C#) 尝试连接时出现LDAP C#错误 - LDAP C# error when trying to connect 尝试在C#中构建时出现错误2019 - Error 2019 when trying to build in C# 尝试登录网站C#时出错 - Error when trying to log into website c# 尝试更新外部联接的datagridview中的字段时出错 - Error when trying to update a field in datagridview which is outer join
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM