Create Smart Document solutions in .NET Framework 2.0
Creating a managed Smart Document project or Add-in for Office 2003 is a bit of a headache because of the many configuration problems one might encounter.
Here is a short summary of the prerequisites of such a project on a target system:
What to install |
Microsoft Office 2003 with the following features enabled:
|
Why? |
There are some DLLs in the following folder which are required for Office to be able to load managed solutions: c:\Program Files\Microsoft Office\Office11 |
Explanation |
Office 2003 uses the OTKLoadr.dll library to load Visual Studio customizations, smart documents and smart tags. |
What to install |
Office 2003 PIAs (Primary Interop Assemblies) |
Why? |
This will add the Smart Tag Library to the GAC |
Explanation |
Managed code that implements the ISmartDocument interface requires a reference to the Microsoft.Office.Interop.SmartTag namespace. See: https://msdn.microsoft.com/en-us/library/aa195478(office.11).aspx Download for Office 2003 PIA: https://www.microsoft.com/downloads/details.aspx?familyid=3c9a983a-ac14-4125-8ba0-d36d67e0f4ad&displaylang=en |
What to install |
VSTOR 2005 SE |
Why? |
The VSTO runtime automatically installs the newest version of OTKLOADR.DLL and additionally adds the CLR Lockback registry key ([HKEY_CURRENT_USER\Software\Classes\Interface\{000C0601-0000-0000-C000-000000000046}]). This enables Office 2003 to run .NET 2.0 code, as initially Office 2003 could not do this. |
Explanation |
Download for VSTOR 2005 SE Alternately, one can install the KB907417, which includes the newest version OTKLoadr, and set up the registry key manually. |
What to install |
Extensibility fix |
Why? |
Adds the Extensibility.dll to the GAC. |
Explanation |
This is included in the extensibilityMSM,msi file from KB 908002. https://support.microsoft.com/kb/908002 The IDTExtensibility2 interface is required for all add-ins and automation projects (it includes events like loading, unloading, updating) https://msdn.microsoft.com/en-us/library/extensibility.idtextensibility2.aspx |
What to install |
.NET Framework Runtime 1.1 |
Why? |
See the explanation for “FullTrust” |
Explanation |
Download: |
What to install |
.NET Framework 2.0 |
Why? |
Obviously, the code is written in .NET 2.0 and requires the framework |
Explanation |
Download: https://www.microsoft.com/downloads/details.aspx?familyid=0856EACB-4362-4B0D-8EDD-AAB15C5E04F5&displaylang=en |
What to install |
The installed DLL should be added to the “FullTrust” zone for both .NET 1.1 and .NET 2.0 |
Why? |
Automation code that is executed via the OTKLoadr appears to follow the permission guidelines of .NET 1.1. However, as the solution most likely contains code whose call stack go through the .NET 2.0 Framework (e.g. a simple MessageBox.Show()) , the code needs to be trusted also by the .NET 2.0 Framework |
Explanation |
Add the DLL to the Full Trust zone using the CASPol tool from the .NET Framework: C:\Windows\Microsoft.NET\Framework\v2.0.50727\ and C:\Windows\Microsoft.NET\Framework\v1.1.4322\ CASPol.exe –ag My_Computer_Zone –url “C:\Users\[Username\Local Settings\Application Data\Microsoft\Schemas\[NameSpace]\[Name].DLL” FullTrust |
Here is a sample Visual Studio 2008 project which creates a very basic Smart Document DLL in .NET 2.0. It also contains the manifest and a sample schema:
Comments
- Anonymous
July 25, 2010
What if I have a .NET 4.0 dll, what do I have to do to get it to load? I've not had any luck with this yet. Can you please post a similar example for Office 2007. - Anonymous
August 23, 2010
Hi Otto. Sorry for the delay.The problem in deploying Smart Document solutions is pretty complex for Office 2003 because of an inherent design limitation.Office 2007 and 2010 should not have the same problems. Plus you will need to use the corresponding VSTO version: 2005 SE/ 3.0 for Office 2007, 4.0 for Office 2010.