Exchange Server TechCenter >
Exchange Server Forums
>
Development
>
[EWS/C#] Exception calling Contact.Load() with FirstClassProperties & an ExtendedPropertyDefinition. Something to do with a blank 'FileAs' property?
[EWS/C#] Exception calling Contact.Load() with FirstClassProperties & an ExtendedPropertyDefinition. Something to do with a blank 'FileAs' property?
- I have a problem which I just cannot seem to get to the bottom of and I really would appreciate any help on the matter. Thank you in advance :)
Outline
I have developed a Windows service which retrieves the contacts from a SharePoints list, compares them with the respective folder of contacts in Exchange Server and updates the contacts on both lists using both SharePoint Web Services and Exchange Web Services. I link the contacts by the ID of the contact in the SharePoint list (this ID is added as an extended property to the Exchange contact in order to ensure fine linking). This process all seems to work perfectly and is complete, minus any more bugs which may appear during the testing; however, I have come accross a fairly major problem which I can reproduce, described below.
Problem
When a contact in Exchange Server contains no 'FileAs' property, before my application starts its syncing, everything is fine, however if I add a contact with no 'FileAs' property or edit a contact which has previously not contained a 'FileAs' property I received the following error when stepping over the following statement:
Error:
Microsoft.Exchange.WebServices.Data.ServiceResponseException: The specified value is invalid for property. at Microsoft.Exchange.WebServices.Data.ServiceResponse.InternalThrowIfNecessary() at Microsoft.Exchange.WebServices.Data.ServiceResponse.ThrowIfNecessary() at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute() at Microsoft.Exchange.WebServices.Data.ExchangeService.LoadPropertiesForItems(IEnumerable`1 items, PropertySet propertySet) at Microsoft.Exchange.WebServices.Data.Item.InternalLoad(PropertySet propertySet) at Microsoft.Exchange.WebServices.Data.ServiceObject.Load(PropertySet propertySet) at ShareSync.ExchangeConnector.GetContacts(String strListName, String strUser) in C:\Development\Projects\SharePoint 2007\ShareSync\Final solution\ShareSync\ShareSync\ExchangeConnector.cs:line 146}
Statement:
I assume you may need more code in order to aid me in solving this problem, so below I have provided the value of the 'objContactPropertySet' object and the ExtendedPropertyDefinition (which is a private member variable of my 'ExchangeConnector' class which houses all of the code relating to this problem). There is an actual GUID string in the GUID variable and it is valid, but I have taken it out of the snippet below.<em>objExchangeContact.Load(objContactPropertySet);</em>
objContactPropertySet = new PropertySet(BasePropertySet.FirstClassProperties, objExtendedPropertyDefinition);private static Guid MyPropertySetId = new Guid("[THE GUID STRING"); private ExtendedPropertyDefinition objExtendedPropertyDefinition = new ExtendedPropertyDefinition(MyPropertySetId, "SID", MapiPropertyType.String);
This code does work absolutely fine every time, apart from in the conditions described above - when a contact is added with no 'FileAs' property or when a contact which has previously had no 'FileAs' property is edited (contacts which were added to Exchange Server with no 'FileAs' property before my service started running for the first time seem to be okay).
What i have tried
Seeing as this appears to be a problem specifically with the 'FileAs' field of the Exchange contact being read in and more specifically with this field being blank (or 'null' in the EWS Contact object) and everything works perfectly fine as soon as something is added to the 'FileAs' field in Outlook, I thought the best way to fix this would be to programatically add the 'FileAs' field if it is 'null' or empty, before 'Contact.Load()' is called; thus, I added the following code (there will always be a company name, given name or surname in our contacts, but not necessarily all of those, so I have catered for that in my code, keeping in mind we prefer the 'FileAs' to contain the full name of the contact):
if (objExchangeContact.FileAs == null || objExchangeContact.FileAs == "" || objExchangeContact.DisplayName == null || objExchangeContact.DisplayName == "") { if (objExchangeContact.GivenName != null && objExchangeContact.Surname != null) { objExchangeContact.FileAs = objExchangeContact.GivenName + " " + objExchangeContact.Surname; objExchangeContact.DisplayName = objExchangeContact.GivenName + " " + objExchangeContact.Surname; } else if (objExchangeContact.GivenName != null && objExchangeContact.Surname == null) { objExchangeContact.FileAs = objExchangeContact.GivenName; objExchangeContact.DisplayName = objExchangeContact.GivenName; } else if (objExchangeContact.GivenName == null && objExchangeContact.Surname != null) { objExchangeContact.FileAs = objExchangeContact.Surname; objExchangeContact.DisplayName = objExchangeContact.Surname; } else { objExchangeContact.FileAs = objExchangeContact.CompanyName; objExchangeContact.DisplayName = objExchangeContact.CompanyName; } objExchangeContact.Update(ConflictResolutionMode.AutoResolve); } objContactPropertySet = new PropertySet(BasePropertySet.FirstClassProperties, objExtendedPropertyDefinition); objExchangeContact.Load(objContactPropertySet);This code was placed above the statements which assign the 'objContactPropertySet' variable and call 'Contact.Load()' (as can be seen in the code) and yet I still receive the same exception as provided above, when stepping over the 'Contact.Load()' statement. Oddly, the 'FileAs' field appears in that contact in the folder view in Outlook, but when clicking on the contact itself and viewing 'Edit' mode, the field is not there in the contact. I have tried 'ConflictResolutionMode.AlwaysOverwrite' as well as 'ConflictResolutionMode.AutoResolve' but neither work.
As I say, modifying the 'FileAs' field in Outlook itself fixes this problem, but modifying that field using the code above does not.
Any help really would be much appreciated and if you would like anymore information or code samples please just ask :)
Thank you in advance and I look forward to finally getting to the bottom of this problem.
Regards,
Calum.
Answers
- You are hitting an Exchange 2007 SP1 bug that was fixed in Service Pack 2.
First, EWS in Exchange 2007 SP1 incorrectly reports that the problematic property is FileAs when it really is FileAsMapping. The actual bug though is that some valid values for FileAsMapping are considered invalid by EWS. This has been fixed in SP2.
David Claux | Program Manager - Exchange Web Services- Proposed As Answer byDavid Claux - MSFT Monday, November 02, 2009 7:31 PM
- Marked As Answer byCalumJR 20 hours 56 minutes ago
All Replies
- What version of Exchange are you targeting?
Could you send a trace of the XML that is exchanged between your app and the server? Just set TraceEnabled = true on your ExchangeService instance before the call to Load, and the trace will be emitted to the Output window in Visual Studio (or to the console if your application is a console application).
David Claux | Program Manager - Exchange Web Services - David, can you please reply to this thread as well .
http://social.technet.microsoft.com/Forums/en-US/exchangesvrdevelopment/thread/242f1faa-60b8-4efe-a9d5-40fc8b48b79f - Thank you for the very quick reply David. It is much appreciated. Unfortunately, I couldn't access the server over the weekend, but I am back at work today and can get on with this now. The version of Exchange I am targetting is 2007 Service Pack 1. I set TraceEnabled to 'true' and the following XML was the output:
<EwsLogEntry EntryKind="EwsRequest" ThreadId="11" Timestamp="02/11/2009 09:50:11 "> <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m=" http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://sc hemas.microsoft.com/exchange/services/2006/types" xmlns:soap="http://schemas.xml soap.org/soap/envelope/"> <soap:Header> <t:RequestServerVersion Version="Exchange2007_SP1" /> </soap:Header> <soap:Body> <m:GetItem> <m:ItemShape> <t:BaseShape>AllProperties</t:BaseShape> <t:AdditionalProperties> <t:ExtendedFieldURI PropertySetId="b3c54e16-95b7-4576-b616-50999d204 5a4" PropertyName="SID" PropertyType="String" /> </t:AdditionalProperties> </m:ItemShape> <m:ItemIds> <t:ItemId Id="AAMkADY4NWNjZmNhLWI4YmYtNGM3MS04YjVlLTkzNjU0NzU5NWI3MwBG AAAAAABqs2+QcYMoSJszQ/Pz27ZmBwAsX9aoRrTdT4QvFrzAyNmyABYA2qOiAAAsX9aoRrTdT4QvFrzA yNmyABYU+5q7AAA=" ChangeKey="EQAAABYAAAAsX9aoRrTdT4QvFrzAyNmyABYU/zKg" /> </m:ItemIds> </m:GetItem> </soap:Body> </soap:Envelope> </EwsLogEntry> <EwsLogEntry EntryKind="EwsResponseHttpHeaders" ThreadId="11" Timestamp="02/11/2 009 09:50:11">200 OK Content-Encoding: gzip Vary: Accept-Encoding Content-Length: 583 Cache-Control: private, max-age=0 Content-Type: text/xml; charset=utf-8 Date: Mon, 02 Nov 2009 09:50:11 GMT Server: Microsoft-IIS/7.0 X-AspNet-Version: 2.0.50727 X-Powered-By: ASP.NET </EwsLogEntry> <EwsLogEntry EntryKind="EwsResponse" ThreadId="11" Timestamp="02/11/2009 09:50:1 1"> <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xs i="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/ XMLSchema"> <soap:Header> <t:ServerVersionInfo MajorVersion="8" MinorVersion="1" MajorBuildNumber="3 40" MinorBuildNumber="0" Version="Exchange2007_SP1" xmlns:t="http://schemas.micr osoft.com/exchange/services/2006/types" /> </soap:Header> <soap:Body> <m:GetItemResponse xmlns:t="http://schemas.microsoft.com/exchange/services /2006/types" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messag es"> <m:ResponseMessages> <m:GetItemResponseMessage ResponseClass="Error"> <m:MessageText>The specified value is invalid for property.</m:Messa geText> <m:ResponseCode>ErrorInvalidValueForProperty</m:ResponseCode> <m:DescriptiveLinkKey>0</m:DescriptiveLinkKey> <m:MessageXml> <t:FieldURI FieldURI="contacts:FileAs" /> </m:MessageXml> <m:Items /> </m:GetItemResponseMessage> </m:ResponseMessages> </m:GetItemResponse> </soap:Body> </soap:Envelope> </EwsLogEntry>
This is placed just before the 'Load()' function, after I programatically assign a 'FileAs' property (as shown in the code sample from the first post). I hope this helps to diagnose the issue and look forward to a response. Thank you once again for your help. - You are hitting an Exchange 2007 SP1 bug that was fixed in Service Pack 2.
First, EWS in Exchange 2007 SP1 incorrectly reports that the problematic property is FileAs when it really is FileAsMapping. The actual bug though is that some valid values for FileAsMapping are considered invalid by EWS. This has been fixed in SP2.
David Claux | Program Manager - Exchange Web Services- Proposed As Answer byDavid Claux - MSFT Monday, November 02, 2009 7:31 PM
- Marked As Answer byCalumJR 20 hours 56 minutes ago
- Thank you very much for all of your help David; it is very much appreciated. I have informed my supervisor of this issue (he is currently out of the country) and hopefully we can upgrade Exchange Server and get this working :)
I have one more issue related to updating the email address property through EWS, which I will create another thread for, in case the cause of that is unrelated to this cause. - We are currently looking to upgrade to this next Tuesday (which is when I will be able to check that this now works) but my supervisor would like me to ensure the upgrade does not have any bad side effects and will not break anything; presumably it won't, but if it does I assume it would tell us in the release notes?
Please refer to the release notes.
David Claux | Program Manager - Exchange Web Services- Thank you :) I apologise for the late reply - I have been away. My boss decided, after browsing the release notes, we will not be upgrading to Exchange 2007 SP2, at least at this time. The 'FileAs' problem shouldn't be too much of an issue for us because we originally obtain our contacts from our SharePoint list, using EWS and Outlook makes it hard to add a contact without a FileAs property - it comes up with a warning. I have implemented a little bit of code to deal with the problem if somebody does add a contact without a FileAs property and according to my boss, that should be sufficient.
I would like to thank you for your help with this issue and the explanation; seeing as I am unable to upgrade, I will mark your proposed answer as the actual answer because I do not see the cause being anything other than what you have suggested.


