Wednesday, January 9, 2008

Why my VSTO Office 2003 addin doesn't work?

First things you need to know

  1. You can see the list of detected and enabled addins in Outlook in:
    Tools->Options->Other->Advanced Options->COM Add-Ins...
    If there were some error and addin has not been loaded it will be there with unchecked box. This is where you enable disabled addins. When you check addin and click OK - addin will be enabled right away, you don't have to restart Outlook

  2. If addin prevented Outlook from functioning correctly it will be "hard disabled" and put there:
    Help->About Microsoft Office Outlook->Disabled Items...

  3. When addin fails to load, by default, we don't see any info about it or the error details. But we can change it!
  • Open command prompt:
    cmd
  • Type:
    set VSTO_SUPPRESSDISPLAYALERTS=0
  • Run Outlook from that command line, should be like this:
    "c:program filesMicrosoft OfficeOffice11Outlook.exe"

Now if something fails with addin - you will see it.

This will give you good basic to debug why your addin doesn't work.
I recently had a lot of problems with it. I thought about sharing it with you so that you don't have to go through it again :-)
BTW: you won't find those information on any forums or other pages ;-)

Things to verify

  1. Install all required assemblies to GAC. This gives them full permissions so if it's something with permissions now it should work. If it does work - check your CAS settings.

  2. Check manifest file. If you played with solution reorganization, changed names of projects, classes - there will be a problem.
    Take a look at the underlined fragments:

    <assembly xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" manifestVersion="1.0">
      <assemblyIdentity name="Sample.Addin.dll" version="1.0.0.0" />
      <asmv2:entryPoint name="Startup" dependencyName="dependency0">
        <asmv2:clrClassInvocation class="Sample.Addin.OutlookAddin" />
      </asmv2:entryPoint>
      <asmv2:dependency asmv2:name="dependency0">
        <asmv2:dependentAssembly>
          <assemblyIdentity name="Sample.Addin" version="3.2.0.0" publicKeyToken="c45b3b012bedcf43" />
        </asmv2:dependentAssembly>
        <asmv2:installFrom codebase="Sample.Addin.dll" />
      </asmv2:dependency>
    </assembly>

  3. Then take a look at the registry setting in the setup project. Verify all paths.
    Make sure that XXX in keys below are equal to ProgID:
    HKCU/Software/Classes/XXX/CLSID
    and
    HKCU/Software/Microsoft/Office/Outlook/Addins/XXX

  4. Got this:
    "Could not load file or assembly 'Microsoft.Office.Interop.Outlook, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies.
    System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Office.Interop.Outlook, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies...."


    Yeah, had this too :) Make sure that you don't have any Office 2007 applications installed on the development machine. I had SharePoint Designer. Uninstall them and reopen solution. Dependency to office.dll 12.0.0.0 should be gone (verify it in the dependency list in setup project).
    Rebuild setup project.


I think that's it :)
Good luck!


2 comments:

Anonymous said...

Rather than un-installing Office 2007 (which for many isn’t an option!) you can instead register the missing assembly in the GAC.

From a Visual Studio command prompt (elevated to administrator if you are on Vista) you can type in the following…

gacutil /i \Microsoft.Office.Interop.Outlook.dll

The will be “C:\Program Files\Microsoft Visual Studio 9.0\Visual Studio Tools For Office\PIA\Office12″ if you have Visual Studio 2008 installed on your C: drive. For other versions just do a search on your hard drive(s) for this file and register it. Voila!

Sebastian said...

But then you have to include this dll into your application's installer. I removed Designer from dev machine so that I don't have unnecessary references.
BTW: Thanks for the comment!