CRM 2015 SDK:解串器不知道映射到此名称的任何类型

CRM 2015 SDK : The deserializer has no knowledge of any type that maps to this name

我目前正在使用 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 打印的错误:

The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://schemas.microsoft.com/xrm/2011/Contracts/Services:request. The InnerException message was 'Error in line 1 position 12271. Element 'http://schemas.datacontract.org/2004/07/System.Collections.Generic:value' contains data from a type that maps to the name 'http://schemas.microsoft.com/xrm/7.1/Contracts:ConcurrencyBehavior'. The deserializer has no knowledge of any type that maps to this name. Consider changing the implementation of the ResolveName method on your DataContractResolver to return a non-null value for name 'ConcurrencyBehavior' and namespace 'http://schemas.microsoft.com/xrm/7.1/Contracts'.'. Please see InnerException for more details.

经过几次搜索,我发现了 2 个可能的原因:

  1. 启用代理类型:事实是我有执行此操作的代码。所以这对我没有帮助。

    _serviceProxy.EnableProxyTypes();

  2. SDK版本:我看到一些回答说SDK版本7.0会导致这个问题。事实上,我使用的是 7.1 版,我也尝试使用最新的 7.1.1 版。我使用这个 DLL:Microsoft.Xrm.ClientMicrosoft.Xrm.SdkMicrosoft.Crm.Sdk.Proxy

  3. 此元素的类型:我也尝试使用基本字符串作为数据类型。仍然存在序列化问题。

None 这些想法解决了我的问题,现在,我真的不知道我应该研究哪里来解决这个问题。

不是 100% 是什么问题,但我建议您尝试以下方法以查看是否有帮助。

  1. 重新生成您的代理,可能是您的代理已过期,这就是 deserializer has no knowledge of any type that maps to this name.

  2. 的原因
  3. 尝试使用后期绑定,看看它是否有效,如果早期绑定代码中存在问题,有助于缩小范围。例如:

Entity account = new Entity("account"); account.Id = new Guid(""); account["new_link"] = "your value"; service.Update(account);

  1. 断点代码并查看正在更新帐户对象的哪些值,例如确保另一个属性没有奇数值。

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

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

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

希望对大家有所帮助。

我已经通过更新参考文献解决了这个问题Microsoft.Xrm.Tooling.Connector 事实证明,我使用的是与其他 SDK 引用不匹配的旧版本,但在构建程序时它没有崩溃。

您可以使用 NuGet 获取该程序集。 这是项目的URL: https://docs.microsoft.com/es-es/dotnet/api/microsoft.xrm.tooling.connector?view=dynamics-xrmtooling-ce-9