Solved

Exchange WebService - Errorcode ErrorIncorrectUpdatePropertyCount when updateing contact

Posted on 2012-03-23
5
588 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

Do email signature updates give you a headache?

Constantly trying to correctly format email signatures? Spending all of your time at every user’s desk to make updates? Want high-quality HTML signatures on all devices, including on mobiles and Macs? Then, let Exclaimer solve all your email signature problems today!

Question has a verified solution.

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

Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
Exchange server is not supported in any cloud-hosted platform (other than Azure with Azure Premium Storage).
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…
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…

948 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

23 Experts available now in Live!

Get 1:1 Help Now