我目前正在使用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
-
此元素的类型:我也尝试使用基本字符串作为数据类型 . 仍存在实现问题 .
这些想法都没有解决我的问题,现在,我真的不知道我想要解决的问题来解决这个问题 .
3 回答
当使用自己创建的WCF服务时,我将分享我对此问题的解决方案,这些服务使用来自CRM的生成模型 .
使用VS 2017在其他项目中引用WCF服务时,
Add Service Reference
窗口中有一些选项:按"Advanced..."并取消选中Reuse types in referenced assemblies
希望它可以帮到某人 .
此问题可能是未知类型 . 在OrganizationServiceProxy上启用代理类型很重要 . 它解决了类似错误的问题
不是100%问题是什么,但我建议尝试以下,看它是否有帮助 .
重新生成代理,可能是您的代理已过期的情况,这就是
deserializer has no knowledge of any type that maps to this name
的原因 .尝试使用后期绑定只是为了查看是否有效,如果早期绑定代码中存在问题,请帮助缩小范围 . 例如:
Entity account = new Entity("account"); account.Id = new Guid(""); account["new_link"] = "your value"; service.Update(account);