Pie*_*ler 3 c# dynamics-crm dynamics-crm-2015
我目前正在使用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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
在我的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");
}
}
Run Code Online (Sandbox Code Playgroud)
现在,我得到了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 "的非空值.''.有关更多详细信息,请参阅InnerException.
经过几次搜索,我找到了两个可能的原因:
启用代理类型:事实是我有代码来执行此操作.所以这对我无济于事.
_serviceProxy.EnableProxyTypes();
SDK版本:我看到了一些关于SDK 7.0版可能导致此问题的答案.事实是我使用的是7.1版,我也尝试使用最新的7.1.1.我用这个DLL的:Microsoft.Xrm.Client,Microsoft.Xrm.Sdk,Microsoft.Crm.Sdk.Proxy
此元素的类型:我还尝试使用基本字符串作为数据类型.仍存在实现问题.
这些想法都没有解决我的问题而且现在,我真的不知道我想在哪里解决修复这个问题.
不是 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);
此问题可能是未知类型.在OrganizationServiceProxy上启用代理类型很重要.它解决了类似错误的问题
using (OrganizationServiceProxy proxy = new OrganizationServiceProxy(organizationUri, null, credentials, null))
{
proxy.EnableProxyTypes();
}
Run Code Online (Sandbox Code Playgroud)