Click here to Skip to main content
15,885,074 members
Articles / Programming Languages / C#
Article

Solutions to Common Issues encountered during Outlook Add-in development.

Rate me:
Please Sign up or sign in to vote.
4.96/5 (14 votes)
1 Dec 20065 min read 109.7K   45   18
Discusses solutions to some of the common issues encountered during Outlook Add-In development.

Introduction

In this article I intend to share some of the common issues encountered during Outlook Add-in (VSTO) development and how these may be addressed. There is interesting information available out there on the web that would help out the VSTO community and I have also tried to provide the links to these articles.

Common Issues

Is there a simpler way to add Prerequisites for VSTO through VS2005?

In an earlier article Walkthrough - Automatic Update Process for Outlook Add-in Solutions, I had discussed setting up the prerequisites through the Launch Conditions Editor. This may be a time-consuming process and may have to be repeated for other VSTO projects.

I found some interesting information here on how you can achieve it by selecting the VSTO pre-requisites directly in your Setup project. You only have to do it once and it makes life easier.

Read the instructions in file 'InstallNotes.txt' that is included as part of this download on how to set it up on your development machine. Once installed, in VS2005 you have to right click the 'VSTO Setup' project and selected 'Properties'. Click on the 'Prerequisites' button that would pop-up something similar to the screen shot shown below.

Prerequisites for VSTO

Click here to download Visual Studio Tools for Office runtime (vstor.exe).
Click here to download Office 2003 Primary Interop Assemblies (PIA) redistributable (O2003PIA.exe).

How do I Sign an Assembly prior to deployment in VS2005?

Your VSTO application needs to be signed with a strong name prior to deployment. To sign the assembly in VS2005, follow these steps:

  • Right-click your VSTO project and under Properties, select the Signing option.
  • Choose New and provide the key file name accordingly.
  • Uncheck the box that protects the key file with a password.

    Signing Assembly

How do I manually setup code access security (CAS) policy?

Once you have the .msi file generated from your VSTO Setup project, you are all set to install your solution. But you still need to consider what permissions your application requires on the end user machine and this is where CAS policy comes in.

For more information of setting up CAS at the User, Machine and Enterprise levels, refer to the article in this link.

To set up CAS for your application at the "User level", follow these steps:

  • Open Control Panel -> Administrative Tools.
  • Click on Microsoft .NET Framework 2.0 Configuration.
  • Open up Runtime Security Policy node.
  • Open the User policy node.
  • Open the Code Groups folder.
  • Right-Click All_Code group and click New.
  • Enter the Name and Description of your new code group as show below and click Next.

    Create CAS Group

  • Select Strong Name as the appropriate membership condition from the drop down and click on the Import button to retrieve the strong name from the assembly from the location the application was installed.
  • Do not set the Version of the assembly and click Next.
    Note: The procedure to "Sign an Assembly" has been discussed earlier in this article.

    Import public key

  • Select Full Trust as the permission set to your code group.

    CAS permission

    Note: This needs to be handled as part of the installation whereby you need to accomplish the equivalent of running Caspol.exe with no user intervention. Something close to this objective is discussed in the following section.

How do I programmatically configure CAS as part of Installation?

I found a sample code (available in both C# and VB.NET) published here, which may be used to handle CAS programmatically. The author has excellently handled both Install and UnInstall in his code.

Follow these steps:

  • In your VS2005 Solution, add a new Class Library project.
  • Delete the default Class1.cs file created.
  • Add a new Installer Class (SetSecurity.cs)

    Add installer

  • Cut/paste the relevant code from sample into SetSecurity.cs that you just created.
    Note: You will have to include the following 3 namespaces in the SetSecurity.cs class (which were missing)
    C#
    using System.Security;
    using System.Security.Policy;
    using System.Security.Permissions;
  • Configure the PolicyLevel and PermissionSet in the code to your needs.
    C#
    private readonly string installPolicyLevel = "Machine";
    private readonly string namedPermissionSet = "FullTrust";
  • In the Outlook Setup project, the Primary output from SetSecurity project needs to be included and using the Custom Actions Editor you may add it as a Custom Action for Install and UnInstall as shown below.

    Custom Editor for Security

  • Build the Outlook Setup project (which references both your security project and Outlook Add-in project) and Install them on the End-User machine. A snapshot of the Code Access Security (CAS) entry in the .NET Framework 2.0 Configuration is shown below.

    Result CAS

Why is the URL to the deployment server missing in the Manifest file?

A concern normally raised by the user community is that the Manifest file on the .msi installed machine does not have any reference to the published URL. There is a roundabout way to handle this.

Follow these steps:

  • In the screen-shot below, the next version of the release during a Publish in the below Outlook Add-in project would be 2.0.0.8.

    Publish version

  • Right-Click the Outlook Add-in project and do a Publish to some deployment server. Refresh the project and look for a manifest file inside the bin\Release\xxx.publish\xxx_2.0.0.8 folder (where 'xxx' is your Outlook Add-in project name).
  • Open up the manifest file and you would notice that "codebase" has the "complete URL" to the deployment server. This is the one that finally needs to show up in the end user machine.

    Manifest in Bin folder

  • Notice that the setup project shown below has the Primary output from both MyOutlookAddin and SetSecurity projects. We need to exclude the manifest file from the primary output of the Outlook Add-in.
  • Right-click on the Primary Output from Outlook Add-in and select Exclude Filter.

    Exclude Filter

  • Click on Add Filter to exclude the manifest file shown in the primary output.

    Exclude Filter result

  • You now have to manually add the right manifest from the bin folder that was published. Right click on the Setup project and select Add followed by File.

    Add Setup file

  • Navigate to bin\Release\xxx.publish\xxx_2.0.0.8 folder and select the recently published manifest and add it to the project. Open the manifest file to confirm that the URL to the published server exists in the manifest as shown below.

    File Add result

  • Rebuild your setup solution and install it on the end user machine.

Conclusion

The objective of writing this article was to share the information I gathered from both experience and reading what the experts out there had to say, so as to provide a helping hand to the VSTO community.

This way of setting up CAS is good enough for the application to run on one machine. Unfortunately, we cannot expect all end-users to manually set up the CAS for your Outlook Add-in assembly.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Questiondo you know of any outlook ad-on developers? Pin
Member 788177828-Apr-11 13:04
Member 788177828-Apr-11 13:04 
QuestionAddIn fails to load with manually added (published) manifest Pin
Klemens Kanal14-Aug-07 2:37
Klemens Kanal14-Aug-07 2:37 
QuestionHow to get body of new arrived email. Pin
Shashi Shinde1-Mar-07 18:30
Shashi Shinde1-Mar-07 18:30 
Hello friends!

I want to get body of new arrived mail. I'm the beginner. I had tried to get the same by using OnNewMail event. I'm not able to get the body of new mail. But it prompts me whenever new mail arrives.

Here is my code -

void __stdcall CAddin::OnNewMail()
{
MessageBox(NULL,"New Mail Arrived","Success",0);
CComQIPtr<outlook::_application>Application;
CComPtr<outlook::_explorer>Explorer;
Application =m_Application;
Explorer =Application->ActiveExplorer();
CComQIPtr<outlook ::_inspector=""> spInspector;
IDispatch *CurrentItem;
HRESULT hr1 = spInspector->get_CurrentItem (&CurrentItem);
if (FAILED (hr1))
MessageBox(NULL,"get_CurrentItem","ERROR",0);

CComPtr<outlook::_mailitem> MailItem;
MailItem=reinterpret_cast<outlook::_mailitem*>(CurrentItem);
BSTR strbodyofmail;
MailItem->get_Body (&strbodyofmail);
MessageBox (NULL, _com_util::ConvertBSTRToString (strbodyofmail),"",0);
}

Is there any another way to get the body of new arrived mail.
I appreciate your immediate help.

Thanks & regards,

Shashi

Shashikant Shinde

QuestionStep 5: Fails to update local copy from deploy location Pin
Denis bda22-Feb-07 5:10
Denis bda22-Feb-07 5:10 
AnswerRe: Step 5: Fails to update local copy from deploy location Pin
Denis bda28-Feb-07 3:09
Denis bda28-Feb-07 3:09 
GeneralIf Server is OFFLINE - custom update functionality Pin
Sanjeev Thazhathaveetil10-Mar-07 3:29
Sanjeev Thazhathaveetil10-Mar-07 3:29 
Questionstep 5 problem Pin
jdrawmer20-Feb-07 23:41
jdrawmer20-Feb-07 23:41 
AnswerRe: step 5 problem Pin
jalekz21-Feb-07 7:53
jalekz21-Feb-07 7:53 
AnswerRe: step 5 problem [modified] Pin
ElRudinho21-May-08 2:20
ElRudinho21-May-08 2:20 
Generalrecipients, subject, body of a Mail not recognised Pin
Bajrang Singh2-Feb-07 21:03
Bajrang Singh2-Feb-07 21:03 
QuestionUpdate runs from server only Pin
gigaty1-Feb-07 4:18
gigaty1-Feb-07 4:18 
AnswerRe: Update runs from server only Pin
Sanjeev Thazhathaveetil1-Feb-07 5:35
Sanjeev Thazhathaveetil1-Feb-07 5:35 
GeneralRe: Update runs from server only Pin
gigaty5-Feb-07 23:10
gigaty5-Feb-07 23:10 
GeneralInstalling on 2K3 with terminal services Pin
bon73329-Jan-07 18:08
bon73329-Jan-07 18:08 
GeneralUnable to get plug-in to update from server Pin
Jason Hills20-Dec-06 16:19
Jason Hills20-Dec-06 16:19 
AnswerRe: Unable to get plug-in to update from server Pin
Jason Hills21-Dec-06 14:17
Jason Hills21-Dec-06 14:17 
GeneralRe: Unable to get plug-in to update from server [modified] Pin
royal_hale5-Feb-07 11:20
royal_hale5-Feb-07 11:20 
GeneralNow this is more like it. Pin
NormDroid1-Dec-06 22:20
professionalNormDroid1-Dec-06 22:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.