Exchange Server TechCenter > Exchange Server Forums > Development > EWS Managed API: Problems updating Outlook Contact, Key Not Found, only one property to modify errors
Ask a questionAsk a question
 

QuestionEWS Managed API: Problems updating Outlook Contact, Key Not Found, only one property to modify errors

  • Thursday, August 20, 2009 10:49 AMMalkier Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,
    I'm having strange problems when trying to update a user's contact. I'm using this code:

    ExtendedPropertyDefinition[] userFields = new
     ExtendedPropertyDefinition[] { title };
                                                        PropertySet extendedPropertySet = new
     PropertySet(BasePropertySet.FirstClassProperties, userFields);
                                                        
                                                        Contact contact = Contact.Bind(tempService,new
     ItemId(ewsID),extendedPropertySet);
                                                        contact.ExtendedProperties.Where(p => p.PropertyDefinition.Tag == 14917).First().Value = newtitle;
                                                        contact.GivenName = newGivenName;
                                                        contact.Surname = Surname ;
                                                        contact.JobTitle = jobtitle;
                                                        contact.BusinessHomePage = homepage;
                                                        /*contact.EmailAddresses[EmailAddressKey.EmailAddress1] = "email@email.com";
                                                        contact.PhoneNumbers[PhoneNumberKey.MobilePhone] = "1212";
                                                        contact.PhoneNumbers[PhoneNumberKey.BusinessFax] = "2323";
                                                        contact.PhoneNumbers[PhoneNumberKey.BusinessPhone] = "22323";
                                                        contact.PhysicalAddresses[PhysicalAddressKey.Business].City = "city";
                                                        contact.PhysicalAddresses[PhysicalAddressKey.Business].CountryOrRegion = "country";
                                                        contact.PhysicalAddresses[PhysicalAddressKey.Business].PostalCode = "94550";
                                                        contact.PhysicalAddresses[PhysicalAddressKey.Business].Street = "street";*/
    
                                                        
                                                        contact.Update(ConflictResolutionMode.AlwaysOverwrite);
    
    Now sometimes I get a Key Not Found Exception for  contact.PhysicalAddresses[PhysicalAddressKey.Business].City = "city";
    Then at other times it's stepping over those properties just fine but when calling the update method I receive the error: An object within a change description must contain one and only one property to modify. When I comment those sections out (see code) it updates just fine.

    I really don't know what to do about this...
    • Edited byMalkier Thursday, August 20, 2009 10:50 AMdescription updated
    •  

All Replies

  • Thursday, August 20, 2009 12:19 PMMalkier Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    OK, now I found out that it can cause trouble with some properties when the target string value is empty:
    contact.EmailAddresses[EmailAddressKey.EmailAddress1] = "";
     This gives me the "An object within a change description must contain one and only one property to modify" error message.
  • Thursday, August 20, 2009 2:42 PMMalkier Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Seems to be a problem when setting empty values. I get an error when I do this: testContact.SetExtendedProperty(email1, "");
    How can I "empty" the field of a contact?
  • Thursday, August 20, 2009 3:27 PMDavid Claux - MSFT Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    This bug should be fixed in the Release Candidate we published yesterday. Please upgrade to the RC version of the API and try again.
    David Claux | Program Manager - Exchange Web Services
  • Thursday, August 20, 2009 3:44 PMMalkier Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Ok will try this,
    can I also empty a field of a user contact now without triggering an exception?
  • Thursday, August 20, 2009 4:44 PMDavid Claux - MSFT Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Yes, that should be fixed, too.
    David Claux | Program Manager - Exchange Web Services
  • Wednesday, September 02, 2009 8:13 AMMalkier Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    Hi,
    I still get a ServiceResponseException (An object within a change description must contain one and only one property to modify.) with the RC version of the API when I try to do something like this:

    Contact testContact = Contact.Bind(service, new ItemId(Id));
                testContact.PhysicalAddresses[PhysicalAddressKey.Business].City = string.Empty;
    
                
                testContact.Update(ConflictResolutionMode.AlwaysOverwrite);
    
    Am I doing something wrong?
  • Friday, October 30, 2009 10:04 AM321X Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    Hi,
    I still get a ServiceResponseException (An object within a change description must contain one and only one property to modify.) with the RC version of the API when I try to do something like this:

    Contact testContact = Contact.Bind(service, new
     ItemId(Id));
    testContact.PhysicalAddresses[PhysicalAddressKey.Business].City = string .Empty;


    testContact.Update(ConflictResolutionMode.AlwaysOverwrite);
    Am I doing something wrong?
    I've got the same problem!!

    How can we clear an item from the EmailAddressDictionary? This dictionary itself doesn't have a method called remove() what I expected to have...

    Hopefully there is a solution for this problem.
  • Thursday, November 05, 2009 9:11 PMCalumJR Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I also have this problem. When I try to assign the EmailAddress1 an empty string (specifically "" because that is what my program reads in when an email address field is empty in SharePoint), I receive a ServiceResponseException with the message of "An object within a change description must contain one and only one property to modify."

    I think the above problem is unrelated to this problem I am having (http://social.technet.microsoft.com/Forums/en-US/exchangesvrdevelopment/thread/73059e51-c3ab-4bca-a3b1-2c58aa401f48) seeing as I only have the above problem when trying to assign an empty string (I have the problem in the thread I linked to when trying to assign any other value).

    Have any of you two figured out the problem of assigning an empty string to the email address property? Does anybody else know a solution to this? Is it a bug which is still present in the RC version of the API (seeing as that is what I am now using and still getting this error).

    Thank you in advance.
  • Friday, November 06, 2009 6:37 AM321X Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I also have this problem. When I try to assign the EmailAddress1 an empty string (specifically "" because that is what my program reads in when an email address field is empty in SharePoint), I receive a ServiceResponseException with the message of "An object within a change description must contain one and only one property to modify."

    I think the above problem is unrelated to this problem I am having (http://social.technet.microsoft.com/Forums/en-US/exchangesvrdevelopment/thread/73059e51-c3ab-4bca-a3b1-2c58aa401f48 ) seeing as I only have the above problem when trying to assign an empty string (I have the problem in the thread I linked to when trying to assign any other value).

    Have any of you two figured out the problem of assigning an empty string to the email address property? Does anybody else know a solution to this? Is it a bug which is still present in the RC version of the API (seeing as that is what I am now using and still getting this error).

    Thank you in advance.
    Well... I have a workaround but that one is pretty radical. In my code I have 2 scenario's.

    1) Update Existing contact
    2) Add new contact.

    The logic in both scenarios is the same and differ at one point. In the first case the contact object is a reference to a loaded contact object and the second case just a new instance.

    The contact information is being set from a datasource obviously.

    If it's scenario 1 I just deleted the existing contact and then follow scenario numer 2 :-) I know this is verrrry dirty but for the time being it works.

    So, my solution : Delete and insert new contact. This way you will never have the 'update one and only one blabla' exception.

    Good luck!
  • Friday, November 06, 2009 6:51 AMMalkier Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Still haven't found a solution to this. Maybe one of the MVPs can advise.
  • Tuesday, November 10, 2009 1:25 PMCalumJR Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Thank you for the suggestion 321X :) I may have to resort to that if I cannot find a fix for this, but hopefully there will be a way for us to just be able to update the email address property.