首页 文章

CRM 2015 SDK:反序列化程序不知道映射到此名称的任何类型

提问于
浏览
3

我目前正在使用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.ClientMicrosoft.Xrm.SdkMicrosoft.Crm.Sdk.Proxy

  • 此元素的类型:我也尝试使用基本字符串作为数据类型 . 仍存在实现问题 .

这些想法都没有解决我的问题,现在,我真的不知道我想要解决的问题来解决这个问题 .

3 回答

  • 4

    当使用自己创建的WCF服务时,我将分享我对此问题的解决方案,这些服务使用来自CRM的生成模型 .
    使用VS 2017在其他项目中引用WCF服务时, Add Service Reference 窗口中有一些选项:按"Advanced..."并取消选中 Reuse types in referenced assemblies

    enter image description here

    希望它可以帮到某人 .

  • 5

    此问题可能是未知类型 . 在OrganizationServiceProxy上启用代理类型很重要 . 它解决了类似错误的问题

    using (OrganizationServiceProxy proxy = new OrganizationServiceProxy(organizationUri, null, credentials, null))
    {
       proxy.EnableProxyTypes();
    }
    
  • 0

    不是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);

    • 断开代码并查看帐户对象上正在更新的值,例如确保另一个属性没有奇数值 .

相关问题