Microsoft Office 2003 Smart Tag Software Development Kit
Frequently Asked Questions [Office 2003 SDK Documentation]

Is there a public newsgroup for the discussion of smart tags?

How do I debug to find out if my managed-code smart tag cannot be loaded because I didn't correctly set .NET security permission to grant it full trust to run?

Attach the debugger to the Office application you want to debug, for example Winword.exe. In Microsoft Visual Studio® 2003, on the Debug menu, click Exceptions. In the Exceptionsdialog box, select Common Language Runtime Exceptions and in the When the exception is thrown list, select Break into the debugger . Next, in Visual Studio 2003, hit F5. At first you will get two exceptions related to msosec (if you have more than one managed smart tag installed, you will get more than two msosec related exceptions). Click Continue. You should get a log.

Your log will look something like below for msosec:

A first chance exception of type 'System.IO.FileNotFoundException' occurred in WRDomainSetup Additional information: File or assembly name msosec, or one of its dependencies, was not found.

A first chance exception of type 'System.IO.FileNotFoundException' occurred in WRDomainSetup Additional information: File or assembly name msosec, or one of its dependencies, was not found.

You can safely ignore the above as they are expected. Check if your managed smart tag is loaded. If the problem is related to permission issues, you will get the following policy exceptions:

A first chance exception of type 'System.Security.Policy.PolicyException' occurred in mscorlib.dll Additional information: Execution permission cannot be acquired.

A first chance exception of type 'System.Security.Policy.PolicyException' occurred in Unknown Module. Additional information: Execution permission cannot be acquired.

A first chance exception of type 'System.Security.Policy.PolicyException' occurred in Unknown Module. Additional information: Execution permission cannot be acquired.

A first chance exception of type 'System.Security.Policy.PolicyException' occurred in Unknown Module. Additional information: Execution permission cannot be acquired.

You can also debug permission issues by looking at combination call stacks, modules, outputs, and so forth and use them to diagnose and narrow down the problems. For example, instead of clicking Continue, click Break, then OK. Next, on the Debug menu, point to Windows and then click Call Stack or Module and so on to analyze the output. After breaking, when you want to continue, hit F5. Whenever you want to break, click Break at the exception point you want to analyze.

The following is an example output file for the IBuySpySmartTag sample showing a successful loading of the managed ibuyspysmarttag_csharp.dll (as denoted by the message 'IBuySpySmartTag_CSharp': Loaded 'c:\documents and settings\user\local settings\application data\assembly\dl2\ljp2r6jm.0m0\k4xjt2yt.nw7\ba930a93\00642ea1_9f62c301\ibuyspysmarttag_csharp.dll', Symbols loaded):


'DefaultDomain': Loaded 'c:\windows\microsoft.net\framework\v1.1.4322\mscorlib.dll', No symbols loaded.
'DefaultDomain': Loaded 'WRDomainSetup', No symbols loaded.
'DefaultDomain': Loaded 'c:\windows\assembly\gac\system\1.0.5000.0__b77a5c561934e089\system.dll', No symbols loaded.
 A first chance exception of type 'System.IO.FileNotFoundException' occurred in WRDomainSetup

Additional information: File or assembly name msosec, or one of its dependencies, was not found.

A first chance exception of type 'System.IO.FileNotFoundException' occurred in WRDomainSetup

Additional information: File or assembly name msosec, or one of its dependencies, was not found.

'Domain2': Loaded 'c:\windows\microsoft.net\framework\v1.1.4322\mscorlib.dll', No symbols loaded.
'IBuySpySmartTag_CSharp': Loaded 'WRDomainSetup', No symbols loaded.
'IBuySpySmartTag_CSharp': Loaded 'c:\windows\assembly\gac\system
\1.0.5000.0__b77a5c561934e089\system.dll', No symbols loaded.
'IBuySpySmartTag_CSharp': Loaded 'c:\windows\assembly\gac\system.drawing1.0.5000.0__b03f5f7f11d50a3a\system.drawing.dll', No symbols loaded.
'IBuySpySmartTag_CSharp': Loaded 'c:\windows\assembly\gac\system.data
\1.0.5000.0__b77a5c561934e089\system.data.dll', No symbols loaded.
'IBuySpySmartTag_CSharp': Loaded 'c:\windows\assembly\gac\system.directoryservices
\1.0.5000.0__b03f5f7f11d50a3a\system.directoryservices.dll', No symbols loaded.
'IBuySpySmartTag_CSharp': Loaded 'c:\windows\assembly\gac\system.messaging
\1.0.5000.0__b03f5f7f11d50a3a\system.messaging.dll', No symbols loaded.
 'IBuySpySmartTag_CSharp': Loaded 'c:\windows\assembly\gac\system.serviceprocess
\1.0.5000.0__b03f5f7f11d50a3a\system.serviceprocess.dll', No symbols loaded. 
'IBuySpySmartTag_CSharp': Loaded 'c:\documents and settings\user\local settings\application data\assembly
\dl2\ljp2r6jm.0m0\k4xjt2yt.nw7\ba930a93\00642ea1_9f62c301\ibuyspysmarttag_csharp.dll', Symbols loaded.
'IBuySpySmartTag_CSharp': Loaded 'c:\windows\assembly\gac\microsoft.office.interop.smarttag
\11.0.0.0__71e9bce111e9429c\microsoft.office.interop.smarttag.dll', No symbols loaded.
 'IBuySpySmartTag_CSharp': Loaded 'c:\windows\assembly\gac\system.xml
\1.0.5000.0__b77a5c561934e089\system.xml.dll', No symbols loaded.
'IBuySpySmartTag_CSharp': Loaded 'c:\windows\assembly\gac\system.windows.forms
\1.0.5000.0__b77a5c561934e089\system.windows.forms.dll', No symbols loaded. 
'IBuySpySmartTag_CSharp': Loaded 'c:\windows\assembly\gac\system.web.services
\1.0.5000.0__b03f5f7f11d50a3a\system.web.services.dll', No symbols loaded. 

In the foregoing example, all the assemblies (smart tag assembly, PIAs) were successfully loaded. If your managed smart tag assembly calls into other assemblies, you will need to grant them full trust permissions as well and check that they also get loaded. For more information on granting explicit full trust permissions to IAs and dependent assemblies, see Granting Full Trust Permissions to Interop and Dependent Assemblies topic.

I have built my unmanaged-code smart tag DLL using the sample code from the Smart Tag SDK, but it does not work! Why is that?

The first step is to make sure that your recognizer is being loaded by Microsoft® Office Word or Excel. Go to the Smart Tags tab of the AutoCorrect Options dialog box (Tools menu) to see if the name of your recognizer is listed along with the other recognizers.

If it is not, here are the possible reasons, listed in the order of likelihood:

  1. Security settings are configured to prevent smart tags from operating.

    Unsigned smart tag DLLs won't run if your security level is set to High, with the Trust all installed add-ins and templates check box cleared. At this security setting, all unsigned smart tag DLLs are disabled automatically. To find out how to run unsigned smart tags, see the Running Unsigned Add-in Samples topic. For more information on Office security, see the "Security" section.

  2. The application was not closed and reopened after compiling.

    As long as one copy of smart tag supporting application is opened, there is the potential that the smart tag registry is not rechecked by these applications when booting new instances of any of these applications. The best solution is to go to your Task Manager (CTRL+ALT+DEL), click the Processes tab, and end all of the OUTLOOK.EXE, WINWORD.EXE, EXCEL.EXE, POWERPNT.EXE and MSACCESS.EXE processes that you see. There is also an off-chance that smart tags are being used by Microsoft Internet Explorer if you have navigated to a page with smart tags on it (especially if you are using MSN Smart Tags), so you may want to end IEXPLORE.EXE processes as well.

  3. One of your smart tag DLLs crashed at a critical point (for example, when loading Word or Excel) and was therefore disabled.

    To check to see if your smart tag DLL is disabled, look at the registration location in your registry at HKCU\Software\Microsoft\Office\Common\Smart Tag\Recognizers\{your Smart Tag CLSID or Namespace.ClassName}

    Note  For registry key values and details of disabled or crashed smart tags, see the Disabling\Enabling Individual Smart Tag DLLs and Crashed Smart Tags DLLs topics.

    Try removing the disabled or crashed smart tag subkey and see what happens. Does your DLL work now? Does it fail to load, and the disabled or crashed smart tag subkey returns? If it is the latter, something is probably not right with your DLL or there is some problem with your code.
  4. The CLSID of the DLL has changed, and therefore the DLL registration is now inaccurate.

    There is the possibility that your DLLs UUID might have changed. In Visual Basic, the UUID's generation is determined by your project's compatibility settings. If the Version Compatibility option on the Component tab of the Properties submenu (Project menu) is set to No Compatibility, a new CLSID is generated every time you compile. This will quickly lead to your smart tag registration to be no longer correct. For the CLSID to remain the same every time you recompile, set it to Project Compatibility or Binary Compatibility. Update your smart tag registration accordingly.

  5. Your DLL is not registered properly.

    Either recompile or regsvr32 it. To regsvr32 a DLL, click Run on the Start menu. As an example, for the SimpleTerm.dll type "regsvr32 c:\SimpleTerm\SimpleTerm.dll" in the Open box of the Run dialog box. Better still, ensure a clean registration by running regsvr32 /u <old path\my dll>, copy it to a new location, and run regsvr32 <new path\my dll>. For example, "regsvr32 /u c:\SimpleTerm\SimpleTerm.dll". If the new location is c:\NewPath\SimpleTerm.dll then, "regsvr32 c:\SimpleTerm\SimpleTerm.dll". Note that this registers your DLL in the HKEY_CLASSES_ROOT\{your smart tag ProgID}\Clsid key in the registry. You would still need to register your DLL in the HKEY_CURRENT_USER\Software\Microsoft\Office\Common\Smart Tag\{your smart tag CLSID} key. See Register the Simple Term DLL topic, under the Visual Basic Tutorial: Creating a List Recognizer and Action topic on how to do this.

If you have taken care of these problems and your smart tag still doesn't work, there are some additional troubleshooting techniques:

  1. It is possible that your recognizer is working but your action DLL is not. If nothing registers actions against a certain smart tag type, and there is no DownloadURL specified, then the Smart Tag Actions button will not show up. To verify this hypothesis, start Word. Type in some terms you know should be recognized by your DLL. Start the Visual Basic Editor (Alt+F11). In the Immediate window, type "for each st in activedocument.SmartTags: debug.Print st.name: next" and press ENTER. Do you see your smart tag type for those terms you typed in Word listed? If so, recognition is working fine but there is something wrong with your action DLL.
  2. Set breakpoints starting with the Class_Initialize or SmartTagInitializemethod in Visual Basic, and see if your DLL is being called into. If it is, perhaps you might find that your DLL is silently failing somewhere.
  3. Try adding your smart tag manually in Visual Basic for Applications (VBA) to see what happens and if your action DLL is working. For example start Excel. Select cell A1. Enter some text. Leave cell A1 selected. Press Alt+F11. Type "Selection.SmartTags.Add {my smart tag type}" into the Immediate Window, and press ENTER. Go back to Excel. Are your smart tag actions there? If so, your smart tag actions are working fine but perhaps your smart tag recognizer is malfunctioning.
Why do I sometimes see question marks in the text being passed to my recognizer from Word?

To improve performance, when the user types in Word, Word creates a buffer into which their typing will go in order to avoid repeatedly doing memory allocation. The empty portion of this buffer is filled with characters (the Unicode value FFFC, which is the object replacement character) which print as question marks, but which indicate that there is empty space left in the buffer. Your recognizer can ignore those characters. The same character is used in the middle of a string that contains an object that is not itself a character, such as an image or OLE object. This code snippet eliminates these characters from the end of the string Text and replaces those in the middle with spaces, which makes "tokenizing" the text easier:

Dim position as Integer
Dim Length as Integer

' Check for characters used in word to mark empty space in the
' buffer. If any of those characters are present at the end
' of Text, then eliminate them.
   length = Len(Text)
    If (length > 0) Then
        position = InStr(1, Text, ChrW(-4))
    Else
        position = 0
    End If
    
    While (length > 0 And position > 0)
        Mid$(Text, position, 1) = " "
        length = length - 1
        If (length > 0) Then
            position = InStr(1, Text, ChrW(-4))
        Else
            position = 0
        End If
        position = InStr(1, Text, ChrW(-4))
    Wend
    Text = RTrim(Text)

position = InStr(1, Text, ChrW(-4))
If (position > 0) Then
    length = Len(Text)
    Mid$(Text, position, (length - position + 1)) = Space$(length - position + 1)
    Text = RTrim(Text)
End If

You might be tempted to optimize for performance using a code snippet like the one below so that your recognizer only runs when the user is finished editing a paragraph. However, a recognizer that attempts to do this will miss the opportunity to smart tag some text, since edit operations in Word that remove the object replacement characters from the end of a string do not cause the text to be passed to the recognizers again.

Dim position as Integer
Dim Length as Integer

position = InStr(1, Text, ChrW(-4))
If (position > 0) Then
    exit sub
End If
How do I create actions that work against those that are packaged into Office 2003?

Writing actions that work against the types recognized by recognizers included with Office (for example, the grammar checker and the stock ticker symbol recognizer) is fairly straightforward. Users need to register their actions against the following smart tag types:

Person urn:schemas-microsoft-com:office:smarttags#PersonName
Stock Ticker Symbol urn:schemas-microsoft-com:office:smarttags#stockticker
Address urn:schemas-microsoft-com:office:smarttags#address
Date urn:schemas-microsoft-com:office:smarttags#date
Place urn:schemas-microsoft-com:office:smarttags#place
Phone Number urn:schemas-microsoft-com:office:smarttags#phone
Time urn:schemas-microsoft-com:office:smarttags#time

There are more labels that the Office grammar checker recognizer provides, like last name and first name. These can be discovered by turning on the grammar checker recognizer, type in some names, then go into the Visual Basic Editor (ALT+F11). You can query to find out what types are being used by typing the following in the Immediate window:

for each st in ActiveDocument.SmartTags: debug.print st.Name: next st
How do I create a Web installation to deploy the DLLs?

The process involves several steps. Essentially, you need to create a web-based ActiveX control (OCX). This OCX is packaged with your smart tag DLLs and is also downloadable via Internet Explorer's CAB mechanism such that when it is downloaded your smart tag DLLs are installed as a by-product. This OCX therefore serves the following roles: a) forces the install of a complete package containing the OCX and your smart tag DLLs, b) writes the registration keys for your DLLs, and c) provides a visual indication when your install is complete. For more detail see the Internet Component Download topic under the Deployment topic.

Is it a known issue that the destructor function in a C# class is not called?

Yes, it is a known issue that the destructor function in a C# class may never be called. Therefore, it is recommended that you avoid placing clean-up code in the destructor function for managed smart tags written in Visual C#. This does not affect smart tags written in Visual Basic .NET as the terminate function for a Visual Basic .NET class generally will be called.

What is the proper way to get the XML property that is returned with a smart tag?

If you take the .Xml property that is returned with a smart tag, it will not include the XML elements that are contained within the tag. It will only contain the XML for other smart tags that are nested. The proper way to get the XML is to take Target.Xml instead.

Must I implement ISmartTagRecognizer2 in the recognizer class and ISmartTagAction2 in the action class to leverage the Visual Studio Tools for Office loader?

No, you don't have to implement ISmartTagRecognizer2 in the recognizer class and ISmartTagAction2 in the action class to leverage the Visual Studio Tools for Office loader. You can still leverage the Visual Studio Tools for Office loader even if you just implement ISmartTagRecognizer or ISmartTagAction only. But you would need the following for it to work:

  1. Microsoft Office 2003
  2. Microsoft .NET Framework 1.1
  3. Full trust permission for the managed-code smart tag DLL
  4. The managed-code smart tag DLL registered using its fully qualified class name, which is Namespace.ClassName in HKEY_CURRENT_USER\Software\Microsoft\Office\Common\Smart Tag\Recognizers\<Namespace.ClassName> and HKEY_CURRENT_USER\Software\Microsoft\Office\Common\Smart Tag\Actions\<Namespace.ClassName>.

    Under those keys, there are two values you need to write:

    • Managed   A DWORD value. A data value of one (1) will enable the managed registry key, signaling that the Visual Studio Tools for Office loader should be used to load that particular assembly. If you don't want to use the Visual Studio Tools for Office loader, set the value to zero (0).
    • Filename   A String value. This string value would be the path to where the managed smart tag DLL is located.

    Note  Because you are using the Visual Studio Tools for Office loader, you don't need to register the managed smart tag DLL for COM Interop at HKEY_CLASSES_ROOT.

What is the best practice for naming my managed smart tag?

To ensure uniqueness, the best practice is to use the fully qualified class name, following the Namespace Naming Guidelines. For example, use CompanyName.Hierarchichal.Namespace.ClassName instead of Namespace.ClassName. For an example on how to do this, see the IBuySpySmartTag Visual C# advanced sample.



Page view tracker