[EWS/C#] 'Microsoft.Exchange.WebServices.Data.ExtendedPropertyCollection' does not contain a definition for 'Add'...
- I just double-checked the version of the EWS API I was using and it turned out I was not using the RC version (I picked up this application from my supervisor who must have started it before the RC was released). It's a stupid oversight from me, but I have now upgraded and am just making my application compatible with the RC version.
I have run into a problem which seems to make no sense to me.
A statement in my code is as follows:
objContactToAdd.ExtendedProperties.Add(objExtendedPropertyDefinition, objContact.GetField(Contact.Field.SID));
A statement in the 'GettingStarted' guide of the API is as follows:
message.ExtendedProperties.Add(extendedPropertyDefinition, "MyValue");
However, I am receiving the following error:
Error 1 'Microsoft.Exchange.WebServices.Data.ExtendedPropertyCollection' does not contain a definition for 'Add' and no extension method 'Add' accepting a first argument of type 'Microsoft.Exchange.WebServices.Data.ExtendedPropertyCollection' could be found (are you missing a using directive or an assembly reference?)
The 'ExtendedProperties' contained an 'Add' method in the old version of the API I was using and my statement worked fine before (although my only parameter was the ExtendedProperty variable which included the definition and value).
Does anybody have any advice/suggestions please? I really would appreciate any help. I have searched around but cannot find anybody else with this problem. The 'Getting Started' guide I am using came with the EWS API RC and I believe the 'ExtendedProperties' should contain an 'Add' method, like the guide suggests and like it did before.
The guide doesn't mention anything about using ExtendedProperty which I used in the old version of the API (when it worked perfectly); it doesn't even seem to allow me to add anything in the parameters of new ExtendedProperty anymore either. If I try to do that, I receive the following error:
Error 1 'Microsoft.Exchange.WebServices.Data.ExtendedProperty' does not contain a constructor that takes '2' arguments.
What could be wrong? I downloaded and installed the API as instructed and copied the 'DLL' and 'XML' files to my 'bin/debug' folder.
Any help really would be appreciated, thank you.
Version of API I am using: 14.00.0639.011
Version of Exchange Server I am targetting (until my supervisor returns to authorise an upgrade): Exchange Server 2007 SP1- Edited byCalumJR Thursday, November 05, 2009 1:14 PM
Answers
- item.ExtendedProperties.Add existed in the Beta release but has been removed in the Release Candidate. item.SetExtendedProperty is the way to go.
David Claux | Program Manager - Exchange Web Services- Proposed As Answer byDavid Claux - MSFT Thursday, November 05, 2009 4:39 PM
- Marked As Answer byCalumJR Thursday, November 05, 2009 8:54 PM
All Replies
- If you read the error message fully, you'll see that you're passing the wrong arguments into the add function. Correct those, and it will work fine.
www.dlpwd.co.uk - Thank you for the reply. The weird thing is, I was passing in the correct arguments, yet it still said I was passing in a single argument of type "Microsoft.Exchange.WebServices.Data.ExtendedPropertyCollection"
I cleaned and re-built the solution but no matter what I tried, the error kept insisting I was passing in that type of argument and only one argument. I originally was, seeing as that worked in the previous version of the API I was using, however, I since corrected this and changed the code to the following (as shown in my first post):
objContactToAdd.ExtendedProperties.Add(objExtendedPropertyDefinition, objContact.GetField(Contact.Field.SID));
Using the above, I still got the exact same error message.
I took all arguments out and still got the exact same error message.
I changed "Add" to "Weird" and got the exact same error message but worded as:
Error 1 'Microsoft.Exchange.WebServices.Data.ExtendedPropertyCollection' does not contain a definition for 'Weird' and no extension method 'Weird' accepting a first argument of type 'Microsoft.Exchange.WebServices.Data.ExtendedPropertyCollection' could be found (are you missing a using directive or an assembly reference?)
I understand this must somehow be a problem on my part/side, but I just cannot seem to see what it could be? I have since changed the statement to:objContactToAdd.SetExtendedProperty(objExtendedPropertyDefinition, objContact.GetField(Contact.Field.SID));
The above seems to work fine (although I need to do more testing), but I would really like to get to the bottom of why this was happening to me when trying to access the 'Add' method. The 'Add' method won't even show in IntelliSense to me, but it obviously has to others and the guide even says it is supposed to be there. I know it's not all about IntelliSense, but using the correct parameters still gives me the same error message (saying I'm passing in an ExtendedPropertiesCollection when I am not).
If anybody could help me get to the bottom of this I would really appreciate it. I'm starting to think it could be something to do with my Visual Studio configuration, but I have never had such problems before.
Thanks,
Calum. - item.ExtendedProperties.Add existed in the Beta release but has been removed in the Release Candidate. item.SetExtendedProperty is the way to go.
David Claux | Program Manager - Exchange Web Services- Proposed As Answer byDavid Claux - MSFT Thursday, November 05, 2009 4:39 PM
- Marked As Answer byCalumJR Thursday, November 05, 2009 8:54 PM
- The Exchange Web Services Managed API 1.0 SDK November 2009 (released yesterday Nov 4 on MSDN) contains code examples showing the correct (new) way to work with extended properties. See this topic for info on creating extended properties: http://msdn.microsoft.com/en-us/library/dd633654.aspx .
Regards,
Kim Brandl
Programming Writer, Microsoft Exchange Developer Documentation Team - Thank you David :) Luckily I figured out earlier that I probably had to use 'item.SetExtendedProperty' but I didn't realise the 'GettingStarted' guide could have errors in (still containing code samples which only work with the beta). I'm certainly not complaining about that, after all it is pre-release, but that is why I was very confused about the situation.Thank you once again for the clarification and reply.
- That is very useful Kim; thank you for linking and informing me :)


