c# - 在使用早期绑定(bind)实体 CRM SDK 2015 的 UpdateObject 时在 SaveChanges 上出错

标签 c# dynamics-crm dynamics-crm-online dynamics-crm-2015

我在 xrm.saveChanges() 上遇到错误如果我执行 UpdateObjectAddObject 工作正常,最初我认为这是因为本线程 Dynamics CRM saving Entity Changes - Getting Errors 中讨论的上下文 但我尝试了这里讨论的所有选项 https://msdn.microsoft.com/en-us/library/gg695783.aspx 但没有任何帮助。

我的代码是`

        using (var xrm = new XrmServiceContext("Xrm"))
        {
            WriteExampleContacts(xrm);

            //Create a new contact called Allison Brown.
            var allisonBrown = new Xrm.Contact
            {
                FirstName = "Allison",
                LastName = "Brown",
                Address1_Line1 = "23 Market St.",
                Address1_City = "Sammamish",
                Address1_StateOrProvince = "MT",
                Address1_PostalCode = "99999",
                Telephone1 = "12345678",
                EMailAddress1 = "allison.brown@example.com"
            };

            xrm.AddObject(allisonBrown);
            xrm.SaveChanges();

            WriteExampleContacts(xrm);



        //Update the e-mail address of Allison Brown and link her to the account Contoso.

        //allisonBrown.contact_customer_accountsParentCustomerAccount = account;
        using (var xrm2 = new XrmServiceContext("Xrm"))
        {

            xrm.Detach(allisonBrown);
            xrm2.Attach(allisonBrown);


            allisonBrown.EMailAddress1 = "allison.brown@contoso.com";
            xrm2.UpdateObject(allisonBrown);
            xrm2.SaveChanges();
        }

        //Update the contact record and then commit the changes to Microsoft Dynamics CRM.
        }

        Console.WriteLine("Press any key to exit.");
        Console.ReadKey();
    }

    /// <summary>
    /// Use all contacts where the email address ends in @example.com.
    /// </summary>
    private static void WriteExampleContacts(XrmServiceContext xrm)
    {
        var exampleContacts = xrm.ContactSet
            .Where(c => c.EMailAddress1.EndsWith("@example.com"));

        //Write the example contacts.
        foreach (var contact in exampleContacts)
        {
            Console.WriteLine(contact.FullName);
        }
    }

我得到的错误是

> Microsoft.Xrm.Sdk.SaveChangesException was unhandled
  HResult=-2146233088
  Message=An error occured while processing this request.
  Source=Microsoft.Xrm.Sdk
  StackTrace:
       at Microsoft.Xrm.Sdk.Client.OrganizationServiceContext.SaveChanges(SaveChangesOptions options)
       at Microsoft.Xrm.Sdk.Client.OrganizationServiceContext.SaveChanges()
       at MuslimAidConsoleApplication.Sample.Main(String[] args)           at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.ServiceModel.FaultException
       HResult=-2146233087
       Message=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 12522. 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.
       Source=mscorlib

任何帮助将不胜感激

最佳答案

尝试使用这个版本... 它对我有用...

SDK 版本 7.0.a 2014 年 10 月

http://www.filedropper.com/microsoftdynamicscrm2015sdk

关于c# - 在使用早期绑定(bind)实体 CRM SDK 2015 的 UpdateObject 时在 SaveChanges 上出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31151331/

相关文章:

c# - 在 WPF 中显示选定的 ComboBox 项

c# - 复选框列表选中的值

javascript - 隐藏 Resco Mobile CRM 中的选项

dynamics-crm-2011 - Microsoft CRM 2011 Online Fetchxml 加载到 CRM 时报告错误

c# - 我可以使用带输出参数的 Action<> 或 Func<> 吗?

c# - 从 C# 类生成 UML 图

JavaScript/Dynamics CRM : Need help finishing JavaScript event that counts how many records in a grid's "Id & Qualify" field ="Yes"

c# - 在 CRM 4.0 中检索单个 Guid

dynamics-crm - Microsoft Dynamics CRM 365:无明显原因生成数百万个联系人

dynamics-crm-2011 - 从 iframe 填充 CRM 表单字段