Solved

Exchange WebService - Errorcode ErrorIncorrectUpdatePropertyCount when updateing contact

Posted on 2012-03-23
5
595 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
ID: 37760784
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
ID: 37760787
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
ID: 37760802
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
ID: 37820765
I have found the problem.
For empty values, I have to set null instead of "".
0
 

Author Closing Comment

by:tkehl
ID: 37836682
It is the right solution.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Exchange 2013 DL hack 4 32
Return array 3 19
C# LINQ 5 18
Exchange 2016 - not receiving mail 17 35
Follow this checklist to learn more about the 15 things you should never include in an email signature from personal quotes, animated gifs and out-of-date marketing content.
Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
To show how to generate a certificate request in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.:  First we need to log into the Exchange Admin Center. Navigate to the Servers >> Certificates…
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…

685 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