【发布时间】:2015-11-17 17:37:12
【问题描述】:
我目前正在使用 CRM 2015 SDK。我只是想用这个 SDK 更新 C# 中的值。但是由于某些我试图弄清楚的原因,当我保存我的context 时出现了问题。
有代码:
foreach (KeyValuePair<string, Account> account in dicAccount)
{
//Calcul of url/login/date/key/customer values
string generatedUrl = Utilities.GenerateURL(url, login, date, key, customer);
account.Value.new_Link = generatedUrl;
if (!context.IsAttached(account.Value))
{
context.Attach(account.Value);
}
context.UpdateObject(account.Value);
}
SaveChangesResultCollection results = context.SaveChanges(SaveChangesOptions.ContinueOnError);
if (results != null)
{
foreach (SaveChangesResult result in results)
{
Type type = result.Request.GetType();
bool hasError = result.Error != null;
Entity entity = (Entity)result.Request.Parameters["Target"];
if (type == typeof(UpdateRequest))
{
if (hasError)
{
if (entity != null)
{
log.Error(result.Error.Message);
}
}
}
在我的 Dynamics 实体上,我有这个:
[Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute("new_link")]
public string new_Link
{
get
{
return this.GetAttributeValue<string>("new_link");
}
set
{
this.OnPropertyChanging("new_link");
this.SetAttributeValue("new_link", value);
this.OnPropertyChanged("new_link");
}
}
现在,我得到了 LogError 打印的这个错误:
格式化程序在尝试反序列化消息时抛出异常:尝试反序列化参数http://schemas.microsoft.com/xrm/2011/Contracts/Services:request 时出错。 InnerException 消息是“第 1 行位置 12271 中的错误。元素“http://schemas.datacontract.org/2004/07/System.Collections.Generic:value”包含映射到名称“http://schemas.microsoft.com/xrm/7.1/Contracts:ConcurrencyBehavior”的类型的数据。反序列化器不知道映射到此名称的任何类型。考虑更改 DataContractResolver 上 ResolveName 方法的实现,以返回名称“ConcurrencyBehavior”和命名空间“http://schemas.microsoft.com/xrm/7.1/Contracts”的非空值。”。有关详细信息,请参阅 InnerException。
经过几次搜索,我发现了两个可能的原因:
-
启用代理类型:事实上我有代码可以做到这一点。所以这对我没有帮助。
_serviceProxy.EnableProxyTypes(); SDK 版本:我看到了一些关于 SDK 版本 7.0 可能导致此问题的答案。事实是我使用的是 7.1 版本,我也尝试使用最新的 7.1.1。我使用这个 DLL 的:
Microsoft.Xrm.Client、Microsoft.Xrm.Sdk、Microsoft.Crm.Sdk.Proxy此元素的类型:我也尝试使用基本字符串作为数据类型。仍然存在序列化问题。
这些想法都不能解决我的问题,而且现在,我真的不知道应该去哪里解决这个问题。
【问题讨论】:
标签: c# dynamics-crm dynamics-crm-2015