Accessing extended props throws System.UnauthorizedAccessException

G

GordonS

I have an Outlook 2007 add-in built using C# and Visual Studio 2008 that
presents a custom form region for editing Contacts.

These contacts have custom properties that are set using Exchange Web
Services from another application, but must be read and written to using
Outlook 2007. The application that exports the contacts to exchange creates
custom properties for extra fields supported by our web client application.

Contacts are exported to a public folder. We are using Exchange 2007 SP1
on the server and both the clients are running Office 2007 on Vista.

The good news is that on some PCs the add-in works fine – it can read and
write the extended custom properties set in Exchange. However, on one test
PC we are getting the following error when trying to read any of our extended
properties:

Exception reading property 'DIWOR' = System.UnauthorizedAccessException: The
property
"http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/DIWOR" does not support this operation.
at
Microsoft.Office.Interop.Outlook.PropertyAccessorClass.GetProperty(String
SchemaName)
at
Pilgrim.Office.Outlook.Contact.SDO.ContactDetailsClient.GetMAPIProperty(PropertyAccessor objPA, String sPropertyName)

It should be noted that the exception is only thrown when trying to read
extended properties of a Contact using the method below – reading the
standard properties does not cause a problem.

The code for the GetMAPIProperty() method is as follows:

public static string GetMAPIProperty(MSOutlook.PropertyAccessor
objPA, string sPropertyName)
{
string sValue, sErrorMessage;

sValue = String.Empty;
try
{
object objProperty =
objPA.GetProperty("http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/" + sPropertyName);
if (objProperty != null)
{
sValue = objProperty.ToString();
}
}
catch (Exception ex)
{
<code to log error goes here>
}
....
}

The code to set a MAPI property is much the same:
public static string GetMAPITag(MSOutlook.PropertyAccessor objPA,
string sTagName)
{
try
{
object objProperty =
objPA.GetProperty("http://schemas.microsoft.com/mapi/proptag/" + sTagName);

if (objProperty != null)
{
return objProperty.ToString();
}
else
{
return "";
}
}
catch
{
return "";
}
}

We tried granting Owner privileges to the Anonymous and Default users on the
folder, but as soon as you create a new contact in one of these folders you
can’t read it because of the above exception!

Any help would be greatly recieved
 
J

Ji Zhou [MSFT]

Thanks for using Microsoft Newsgroup Support Service! My name is Ji Zhou
[MSFT]. I am glad to work on this issue with you.

First I want to ensure that I understand your issue correctly. From the
description, I know that there are some custom properties added to Outlook
contacts. The contacts' values are set via Exchange Web Service from
another application. Our Outlook Add-In has created a Form Region which is
used to get and set these custom properties using PropertyAccessor. The
same code works fine in some PCs, but fails in a test PC with a
System.UnauthorizedAccessException thrown. If I have any misunderstanding
about the issue, please feel free to correct me.

In my opinion, since your code looks correct to me and it's also proved
that this Outlook Add-In can work in some PCs without any error. I think
the problem should not be related to the code, but machine or software
configurations. I would like to suggest you perform the following general
troubleshooting steps:

1.From Outlook product team's blog
http://blogs.msdn.com/outlook/archive/2007/12/14/office-2007-sp1-has-arrived
..aspx, we can see Office 2007 SP1 has incorporated further enhancements to
security. So, first thing we need to check is whether the error PC is
installed with Office 2007 SP1. If not, we can try to install SP1 to see if
it fixes the issue.

2.We can try to create a new Outlook profile from Control Panel->Mail->Show
Profiles, and then run Outlook, as well as the Add-In again. This will
eliminate the profile corruption potential.

3.Does Outlook use the same exchange user account when testing in these
different machine? Different AD accounts may have different privileges to
access the exchange store which contains custom property.

And could you please provide some more information about the differences
between the work PC and the error PC? Like the configurations of the
Outlook connection to Exchange, cached or none-cached mode? With some more
detailed information, I can do future research on my side.

Best Regards,
Ji Zhou ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

GordonS

I managed to work around the permissions issue by extending the code that
creates the public folders using Exchange Web Services to allocate Owner
permissions to the Anonymous user. This works for the moment on the
principle that you have to have an e-mail account to see the public folder in
the first place, but I may lower the permission level in time.

There is an event sink that monitors the folders and stops users doing
unwanted things like copying and moving contacts.

The reason for picking the Anonymous user is to ease on the maintenance of
the public folders – it is not anticipated that our customers are going to
want to manage permissions themselves for new users and leaving users.

Getting back on point, I think the problem may have been caused by the
folders being created by the Administrator user and the add-in being run by a
user that had less privileges. I am curious as to why the add-in was able to
read the standard properties of the ContactItem object, but not the extended
properties, though – surely if you can read a contact you should be able to
read all of the data on it?

--
Gordon Smith


"Ji Zhou [MSFT]" said:
Thanks for using Microsoft Newsgroup Support Service! My name is Ji Zhou
[MSFT]. I am glad to work on this issue with you.

First I want to ensure that I understand your issue correctly. From the
description, I know that there are some custom properties added to Outlook
contacts. The contacts' values are set via Exchange Web Service from
another application. Our Outlook Add-In has created a Form Region which is
used to get and set these custom properties using PropertyAccessor. The
same code works fine in some PCs, but fails in a test PC with a
System.UnauthorizedAccessException thrown. If I have any misunderstanding
about the issue, please feel free to correct me.

In my opinion, since your code looks correct to me and it's also proved
that this Outlook Add-In can work in some PCs without any error. I think
the problem should not be related to the code, but machine or software
configurations. I would like to suggest you perform the following general
troubleshooting steps:

1.From Outlook product team's blog
http://blogs.msdn.com/outlook/archive/2007/12/14/office-2007-sp1-has-arrived
.aspx, we can see Office 2007 SP1 has incorporated further enhancements to
security. So, first thing we need to check is whether the error PC is
installed with Office 2007 SP1. If not, we can try to install SP1 to see if
it fixes the issue.

2.We can try to create a new Outlook profile from Control Panel->Mail->Show
Profiles, and then run Outlook, as well as the Add-In again. This will
eliminate the profile corruption potential.

3.Does Outlook use the same exchange user account when testing in these
different machine? Different AD accounts may have different privileges to
access the exchange store which contains custom property.

And could you please provide some more information about the differences
between the work PC and the error PC? Like the configurations of the
Outlook connection to Exchange, cached or none-cached mode? With some more
detailed information, I can do future research on my side.

Best Regards,
Ji Zhou ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Ji Zhou [MSFT]

Hello Gordon,

Thanks for the workaround your post, it will benefit others in future here.
I agree your opinion that the problem may have been caused by the folders
being created by the Administrator user but the add-in being run by a user
that had less privileges. As to why only the custom properties have this
permission issue, while standard properties work fine, is this your main
concern now? I am still performing research on this issue and will get back
to you as soon as possible. I appreciate your patience.


Best regards,
Ji Zhou
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top