Solved

Exchange WebService - Errorcode ErrorIncorrectUpdatePropertyCount when updateing contact

Posted on 2012-03-23
5
603 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
A list of top three free exchange EDB viewers that helps the user to extract a mailbox from an unmounted .edb file and get a clear preview of all emails & other items with just a single click on mailboxes.
In this video we show how to create a Shared Mailbox 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 Recipients >> Sha…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Suggested Courses

627 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