Solved

Exchange WebService - Errorcode ErrorIncorrectUpdatePropertyCount when updateing contact

Posted on 2012-03-23
5
587 Views
Last Modified: 2012-08-13
I use the fallowing method to update a contact in Exchange over EWS:

        private void UpdateContact(Microsoft.Exchange.WebServices.Data.Contact exContact, ContactInfo contact) {
            var pathList = new List<string>();
            try {
                log.DebugFormat("Process ExchangeContact '{0}' with Contact '{1}'", (exContact.IsNew ? "<new>" : exContact.DisplayName), contact.Id);

                exContact.GivenName = contact.AdditionalName;
                exContact.Surname = contact.Name;
                exContact.FileAsMapping = FileAsMapping.SurnameCommaGivenName;

                exContact.CompanyName = "";
                if (contact is PersonInfo) {
                    var person = (PersonInfo) contact;
                    if (person.PersonCompany != null && person.PersonCompany.Company != null) {
                        exContact.CompanyName = person.PersonCompany.Company.DisplayName;
                    }
                    exContact.ImAddresses[ImAddressKey.ImAddress1] = person.MessengerName;
                    exContact.ImAddresses[ImAddressKey.ImAddress2] = person.SkypeName;
                }

                // Specify the business, home, and car phone numbers.
                var comm = contact.GetCommunication(Constants.CommunicationType.PhoneBusiness);
                exContact.PhoneNumbers[PhoneNumberKey.BusinessPhone] = (comm != null ? comm.Value : null);
                comm = contact.GetCommunication(Constants.CommunicationType.PhonePrivate);
                exContact.PhoneNumbers[PhoneNumberKey.HomePhone] = (comm != null ? comm.Value : null);
                comm = contact.GetCommunication(Constants.CommunicationType.PhoneMobile);
                exContact.PhoneNumbers[PhoneNumberKey.MobilePhone] = (comm != null ? comm.Value : null);

                comm = contact.GetCommunication(Constants.CommunicationType.MailBusiness);
                exContact.EmailAddresses[EmailAddressKey.EmailAddress1] = (comm != null ? new EmailAddress(comm.Value) : null);
                comm = contact.GetCommunication(Constants.CommunicationType.MailPrivate);
                exContact.EmailAddresses[EmailAddressKey.EmailAddress2] = (comm != null ? new EmailAddress(comm.Value) : null);

                // Specify two IM addresses.

                // Specify the home address.
                var address = contact.AddressList.FirstOrDefault(x => x.AddressType != null && x.AddressType.Id == Constants.AddressType.Private);
                if (address != null) {
                    var paEntry = new PhysicalAddressEntry
                        {
                            Street = address.Street,
                            City = address.City,
                            State = address.Region,
                            PostalCode = address.PostalCode,
                            CountryOrRegion = address.CountryName
                        };
                    exContact.PhysicalAddresses[PhysicalAddressKey.Home] = paEntry;
                    if (contact.PostalAddress == address) {
                        exContact.PostalAddressIndex = PhysicalAddressIndex.Home;
                    }
                } else {
                    exContact.PhysicalAddresses[PhysicalAddressKey.Home] = null;
                }
                address = contact.AddressList.FirstOrDefault(x => x.AddressType != null && x.AddressType.Id == Constants.AddressType.Business);
                if (address != null) {
                    var paEntry = new PhysicalAddressEntry
                        {
                            Street = address.Street,
                            City = address.City,
                            State = address.Region,
                            PostalCode = address.PostalCode,
                            CountryOrRegion = address.CountryName
                        };
                    
                    exContact.PhysicalAddresses[PhysicalAddressKey.Business] = paEntry;
                    if(contact.PostalAddress == address) {
                        exContact.PostalAddressIndex = PhysicalAddressIndex.Business;
                    }
                } else {
                    exContact.PhysicalAddresses[PhysicalAddressKey.Business] = null;
                }

                // Save the contact.
                if (exContact.IsNew) {
                    exContact.Save();
                } else {
                    exContact.Update(ConflictResolutionMode.AlwaysOverwrite);
                }

                pathList.AddRange(this.AddFileAttachments(this.Access.IndependService.GetContact(exContact.Id.UniqueId), contact.GetDocuments()));
            } catch(Exception e) {
                log.Error("Error updating/inserting Contact in Exchange.", e);
            } finally {
                foreach (var path in pathList) {
                    this.Access.Context.Container.Resolve<IDocumentService>().UndoCheckOut(path);
                }
            }
        }

Open in new window


When I do this for update, I get an Exception with Errorcode ErrorIncorrectUpdatePropertyCount on the line exContact.Update(ConflictResolutionMode.AlwaysOverwrite);

Can someone help me, what is the problem? - Thanks.
0
Comment
Question by:tkehl
  • 3
  • 2
5 Comments
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
Playing both sides to the middle:

http://stackoverflow.com/questions/9844610/exchange-webservice-errorcode-errorincorrectupdatepropertycount-when-updateing

Understanding that error:

ResponseCodeType Enumeration
http://msdn.microsoft.com/en-us/library/exchangewebservices.responsecodetype(v=exchg.140).aspx

Indicates that each change description in an UpdateItem or UpdateFolder method call must list only one property to update.
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
I believe that is one of those errors that isn't helpful.

Another example:

Exchange 2007 Web Services (III): Update a calendar item (UpdateItem)
http://felixmondelo.blogspot.com/2008_08_01_archive.html

Pay attention to this line:

calendarEndItem.End = new DateTime(2008, 08, 28, 17, 00, 00);
calendarEndItem.EndSpecified = true;

If we don't set EndSpecified property, we will receive a confusing error code: ErrorIncorrectUpdatePropertyCount.
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
There is a lot going on there, so it is difficult to see any one thing.  I don't see any loops.  What I would suggest is commenting out the lines that set a property, and then uncomment them until you find the offending line(s).
0
 

Accepted Solution

by:
tkehl earned 0 total points
Comment Utility
I have found the problem.
For empty values, I have to set null instead of "".
0
 

Author Closing Comment

by:tkehl
Comment Utility
It is the right solution.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Resolve Outlook connectivity issues after moving mailbox to new Exchange 2016 server
This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
In this video we show how to create a Resource Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: Navigate to the Recipients >> Resources tab.: "Recipients" is our default selection …
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now