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

时间:2015-08-24 10:20:12

标签: 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); 
                             }
                        }
                   }

在我的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。

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

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

    _serviceProxy.EnableProxyTypes();

  2. SDK的版本:我看到了一些关于SDK 7.0版可能导致此问题的答案。事实是我使用的是7.1版,我也尝试使用最新的7.1.1。我使用此DLL:Microsoft.Xrm.ClientMicrosoft.Xrm.SdkMicrosoft.Crm.Sdk.Proxy

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

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

4 个答案:

答案 0 :(得分:5)

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

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

答案 1 :(得分:4)

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

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

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

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

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

答案 2 :(得分:0)

当使用自己创建的WCF服务(使用CRM生成的模型)时,我将分享我对这个问题的解决方案。
使用VS 2017在其他项目中引用WCF服务时,Add Service Reference窗口中有一些选项:按“高级...”,然后取消选中Reuse types in referenced assemblies

enter image description here

希望它可以帮助某人。

答案 3 :(得分:0)

我已经通过更新裁判Microsoft.Xrm.Tooling.Connector解决了这个问题 原来,我使用的旧版本与其他SDK参考不匹配,但是在构建程序时不会崩溃。

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