Tesfaye_SI

Hello,

I created an application that outputs an html vCard from data stored in a SQL database. It works great as a standalone application on the development machine and other test computers. I was asked to make it run from within Outlook so users could just click a button, customize it, save it and set it as the default signature if they wanted. I've created add-ins in C# for Outlook XP without a problem but since we moved to Outlook 2003 I figured why not use VSTO 2005 and take advantage of the somewhat simpler interface (two events handlers!).

Long story short, I was able to get it to work on the development machine and I have the setup project adding the correct code group security settings and also checking prerequisites. The test machines are giving me a headache. They all have the right security policies in place for the assembly and they all have the VSTO runtimes and Office2003 PIA installed.

I modified the code to display some message boxes and they are shown on the test machines when Outlook loads but once I try to access the Explorer.CommandBars collection the add-in fails without any sort of error and the LoadBehavior value in the registry is set to 2. If I comment out the code for accessing the CommandBars collection the add-in is pretty much useless but it is no longer disabled by Outlook.

I noticed something else that was kind of strange. If I placed a few MessageBox.Show("..."); commands in a method they all fired off in succession but if I threw in a cmdBars = myExplorer.CommandBars at the end of the method, rebuild, install and run on the test computer, the method does not work and the add-in once again is disabled. It works on my development machine.

Any ideas

Thanks,

Tesfaye



Re: Visual Studio Tools for Office Explorer.CommandBars causes VSTO Outlook 2003 add-in to fail. *Pulling hair out!!*

Sue Mosher - Outlook MVP

It might be helpful if you showed a code snippet to demonstrate how you're instantiating the Explorer object and CommandBars objects.



Re: Visual Studio Tools for Office Explorer.CommandBars causes VSTO Outlook 2003 add-in to fail. *Pulling hair out!!*

Mike Walker

Hi

There are a couple of things to suggest here. Firstly COM and .NET have some quirky behaviours at times and if you havent wrapped your code in the Method that the Explorer.CommandBars collection are managed from you will not get an exception as VSTO will handle this and throw out the code. Try Catch this code block and wrapper and see what gets fired.

Additionally there are a couple of Hotfixes for Office that may help

http://support.microsoft.com/kb/907417/

http://support.microsoft.com/kb/908002/en-us

Regards






Re: Visual Studio Tools for Office Explorer.CommandBars causes VSTO Outlook 2003 add-in to fail. *Pulling hair out!!*

Tesfaye_SI

Thanks for responding Sue, here is the code minus the VSTO Generated Code region.

Code Snippet

using System;
using System.Windows.Forms;
using Microsoft.VisualStudio.Tools.Applications.Runtime;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
using System.Runtime.InteropServices;

namespace OutlookAddin2
{
public partial class ThisApplication
{
Outlook.Application oApp;
Outlook.Explorer explorer;
Office.CommandBars cmdBars;
private void ThisApplication_Startup(object sender, System.EventArgs e)
{
MessageBox.Show("Add-in loaded.");
OtherWayToDoIt();//This worked just fine.
oApp = this.ActiveExplorer().Application; //I tried this to see if it would make a difference. It didn't
explorer = oApp.ActiveExplorer(); //On my development machine I have no problems starting from here.
cmdBars = explorer.CommandBars;
int count = cmdBars.Count;
MessageBox.Show(count.ToString());
}

private void OtherWayToDoIt()
{
MessageBox.Show(this.ActiveExplorer().CommandBars.Count.ToString());
}

private void ThisApplication_Shutdown(object sender, System.EventArgs e)
{
}

...VSTO Generated Code removed

}

I did some more testing. I created three different projects that used commandbar objects, two of which I found on the net and they all failed in the same manner. I started thinking that something could be wrong with my VS installation so I setup a VM machine with XP fully patched and installed the Visual Studio Tools for Office and not the full version of Visual Studio 2005. I was able to compile and distribute all of the solutions and run them without a problem. The solutions where I created commandbars and added button controls to them worked just as expected. There must be something wrong with my developement machine's configuration. Well, at least now I can wrap this project up and move on to the next one.

Thanks,

Tesfaye





Re: Visual Studio Tools for Office Explorer.CommandBars causes VSTO Outlook 2003 add-in to fail. *Pulling hair out!!*

Tesfaye_SI

I just read the articles. Interesting stuff, I'll give the patches a shot in the morning. If that doesn't work, I'll have a copy of my VHD on hand containing the working dev environment so I can finish my project and figure out the fate of my current desktop later on.

I love Virtual PC.

Thanks,

Tesfaye





Re: Visual Studio Tools for Office Explorer.CommandBars causes VSTO Outlook 2003 add-in to fail. *Pulling hair out!!*

Mike Walker

Virtual PC - best thing for dev and testing, just need them to put a few features that well known competition product has such as Snapshots Wink

Regards






Re: Visual Studio Tools for Office Explorer.CommandBars causes VSTO Outlook 2003 add-in to fail. *Pulling hair out!!*

Mike Walker

Another thought is does your test environemtn have anything like Windows Mobile / Active Sync installed as this maybe loading a session of Outlook up that is causing the code to work slightly differently, the other thing is to wrapper the complete code in a Try Catch and see if there is a COM Exception being thrown as this may also help diagnose this.

Regards