VSTO & .NET & Excel

December 28, 2006

Creating and Deploying Managed COM Add-ins with VSTO 2005 SE – Part I

Filed under: VSTO & Excel — Dennis M Wallentin @ 8:21 pm

This blogpost, together with some upcoming blogposts, will end the series “The Transition Case” by discussing and viewing the Visual Studio 2005 Tools for Microsoft Office System Second Edition (VSTO 2005 SE) based solution. 

Since I have decided to set focus on VSTO & Excel during 2007 this blogpost is also a start for the series “Creating and Deploying Managed COM add-ins. However, it will not prevent me from continue to discuss .NET & Excel from a broader perspective. I will also later cover how to create and use classic commandbars in Excel 2003 with VSTO 2005 SE solution.  

Before “diving into the world of VSTO” I would like to remind that my recommendation VSTO 2005 SE is still valid mainly due to the present deployment issues. However, I sincerely hope that when version 3.0 of VSTO is shipped these issues have also been solved in a developer friendly way.

#Introduction 
VSTO 2005 SE was released in November 2006 and it provide us with the possibility to create application level add-ins, i e managed COM add-ins, for Excel 2003 and Excel 2007.

The following requirements must be met in order to create and distribute VSTO based add-ins:

  • Visual Studio 2005 Professional or higher or
  • Visual Studio 2005 Tools for Microsoft Office System (VSTO 2005) and
  • Visual Studio 2005 Tools for Microsoft Office System Second Edition (VSTO 2005 SE) and
  • .NET Framework 2.0 and later (also on the targeting computers)
  • VSTO 2005 SE runtime (on the targeting computers)
  • Excel 2003 (certain versions only) and Excel 2007 (all versions)

Special note:
Microsoft strongly recommend to not install VSTO 2005 SE on any computer that have more than one version of Microsoft Office installed.

#Registry entries
One important aspect is that we don’t need to shim the add-ins like we need to do with  Shared Add-ins (developed with VB.NET) since VSTO use an add-in loader file.

The following (Swedish) screenshot shows the entry in the HKEY_CLASSES_ROOT section and under the InprocServer32 subkey:

addinloader.png

Compared with managed/unmanaged COM add-ins the registry entries in the HKEY_CURRENT_USER is the same except that VSTO managed COM add-ins also got a Manifest entry (that points to the Manifest.DLL file for the Add-in) as the following (Swedish) screenshot shows:

manifest.png

 # The Project
The project involved is the same as for the previously Transition case although it does not cover subclassing and reading/writing to the Windows registry.

The following screenshots shows the Solution Explorer for the project:

solution-explorer.png

As we can see it contain a great number of Detected Dependencies.

#The Created skeleton
When creating the VSTO project with the add-in template for Excel 2007 it creates a class module – ThisAddin.vb – which contain only two procedures: 

thisaddin.png

In my opinion this is a welcome improvement as this two events are the ones we usually had used in unmanaged COM Add-ins.  The ExcelLocale1033Proxy class is interesting as it provides two methods we can use to modify the locale ID for individual Excel objects, i e wrap for locale ID 1033 (English United States) and unwrap for another Locale ID, for instance Swedish. An even better approach is to use ExcelLocale1033Attribute which allow us to pass all the native Excel objects locale ID and in that way consider the local regional settings (which was also pointed out as a shortcoming in previously version by Bullen et al in their book “Professional Excel Development”).

In the next blogpost I will discuss more in detail the project itself.

Kind regards,
Dennis

About these ads

12 Comments »

  1. Good stuff Dennis look forward to seeing the next few post, getting into the framework a bit now, it’s a hard slog!
    Hope your good
    Ross

    Comment by Ross — December 29, 2006 @ 12:22 pm

  2. Thanks Ross :)

    Make some investment of Your time to learn .NET and its Framework as it will be paid off when You start to challenge it.

    I believe that MSFT is upto something really good with VSTO but it will probably take off when version 3.0 will be available.

    Meanwhile I will try to “clear the basic mud” ;)

    Take care and all the best from,
    Dennis

    Comment by Dennis Wallentin — December 29, 2006 @ 9:23 pm

  3. hi
    I have followed all the instructions whatever given in this article
    After of all I am getting following error
    “not loaded. A runtime error occured during the loading of the com add-in.”

    Please help me

    Comment by mahendra — February 27, 2007 @ 12:46 pm

  4. Mahendra,

    # Have You installed all the prequisites?
    # What is the outcome when debugging during runtime?

    Kind regards,
    Dennis

    Comment by Dennis Wallentin — February 27, 2007 @ 1:20 pm

  5. Hi Everyone,
    I just converted my Shimmed Excel Add-in from VS2003 to VS2005 and I am getting the same error Mahendra is getting. After reading this post, thank you Dennis, I believe the problem might be because I am building against Excel 2002 rather than 2003. Can someone please confirm that building Add-ins with VS2005 is not allowed with Excel 2002. I also have .net framework 1.1 and 2.0 on the same machine. What are all the prequisites?

    Thanks in advance

    Comment by Jim — April 14, 2007 @ 12:37 pm

  6. Hi Jim,

    Exel 2002 uses .NET Framework 1.1 by default. So when we have both 1.1 and 2.0 installed on the same machine it will cause a similar situation as You experience.

    The solution seems to be to replace all the references to 1.1 in the project and replace them with 2.0 references.

    Let us know what the outcome is.

    Kind regards,
    Dennis

    Comment by Dennis Wallentin — April 14, 2007 @ 12:49 pm

  7. Hi Dennis,

    Thank you for your quick response. The project has references to other projects. These referenced projects have references to third party controls that use 1.1. We will need to update these controls in order to make all my references point to 2.0. I will keep you posted once I have it done.

    Thanks again for the help

    Comment by Jim — April 15, 2007 @ 10:33 am

  8. Thank You

    Comment by Alex — April 25, 2007 @ 12:31 pm

  9. Hi,

    I have created an Excel 2007 Addin using VS 2005. It is working fine in the development machine. But when I try to deploy the add-in, I am also getting following error
    “not loaded. A runtime error occured during the loading of the com add-in.”

    Both the development and deployed machines contains all the .NET framework versions (1.1, 2.0, 3.0 and 3.5) and also Office 2007 installed. VSTO 2005 SE runtime is also installed in both the machines.

    It would be great if some one could help me to figure out the issue.

    Thanks

    Comment by Nataraj — December 17, 2007 @ 8:21 pm

  10. Hi Nataraj,

    When creating a new VSTO project it’s granted full trust on the development machine.

    In order to get it to work on the targeting machines You need to set the code access security (CAS). Please see the following blogpost about it:

    http://xldennis.wordpress.com/2007/03/04/creating-and-deploying-managed-com-add-ins-with-vsto-2005-se-part-vi/

    Kind regards,
    Dennis

    Comment by Dennis Wallentin — December 19, 2007 @ 9:08 pm

  11. What if you have .net v2.0 and .net v3.0 installed ? would that cause the same problem as between v1.0 and 2.0 ?

    thanks

    cmTK.

    Comment by codemasterTK — May 13, 2008 @ 11:29 am

  12. Hi cmTK,

    Version 2.0 and 3.0 are quite similar and 3.0 is backwards compatible which probably will not cause the same issue. I still develop against 2.0 and targeting computers that have only 3.0 available is not a problem for my solutions.

    Kind regards,
    Dennis

    Comment by Dennis Wallentin — May 21, 2008 @ 3:25 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

The Silver is the New Black Theme. Create a free website or blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 36 other followers

%d bloggers like this: