Error loading VB add-ins - token count 0

Q:

I have a problem with loading VB add-ins.

The method call:

ObjectModel::Collection<AddInToken^>^ addInToken = AddInStore::FindAddIn(IEntryPoint::typeid, AddInStoreExtensions::DefaultPipelinePath, FilePath, TypeName);

returns an empty collection when called on a dll created using VB. The FilePath parameter points to a dll, the TypeName is an "ApplicationAddIn.ThisApplication" string where an "ApplicationAddIn" is a RootNamespace of a

VB project, and "ThisApplication" is a class defined in a VB project. The ApplicationAddIn.ThisApplication type is a VS Object Browser in a VB Add-in project.

The C#-based projects works fine, using templates created at the same time. Can you help me with loading VB-based add-ins?

 

 

 

A:

VB add-ins require the proxy to be registered in the VSTA pipeline as well as the GAC; C# add-ins can function without the proxy in the VSTA pipeline.  So you should confirm that the proxy is registered in the VSTA pipeline (C:\Program

Files\Common Files\Microsoft Shared\VSTA\Pipeline\AddInViews).  The SDK samples register the proxy in the pipeline with the file InstallForVB.bat and a post build event which runs it.  Once you have confirmed that the proxy is registered

you can rebuild the pipeline with the code below or through the command prompt.

InstallForVB.bat:

SET TARGET=%1

SET FrameworkDir=%SystemRoot%\Microsoft.NET\Framework\v3.5

 

REM Copy the Proxy Assembly to AddInViews for VB and update Pipeline

copy %TARGET% "%CommonProgramFiles%\microsoft shared\VSTA\Pipeline\AddInViews\"

"%FrameworkDir%\AddInUtil" -PipelineRoot:"%CommonProgramFiles%\microsoft shared\VSTA\Pipeline" -Rebuild

 

Post build event:

call "$(ProjectDir)InstallForVB.bat" "$(TargetPath)"

Code to manually rebuild pipeline:

'CYA- run addinstore update for the pipeline and add-in location

'update the pipeline

Dim warnings() As String = AddInStore.Update(AddInStoreExtensions.DefaultPipelinePath)

If (warnings.Length > 0) Then

    For Each warning As String In warnings

        Console.WriteLine(warning)

    Next

End If

 

'update the add-in discovery folder

Dim warnings2() As String = AddInStore.UpdateAddIns(Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "MyAppVB6"))

If (warnings2.Length > 0) Then

    For Each warning As String In warnings2

        Console.WriteLine(warning)

    Next

End If

 

 

Make sure the proxy dll is in the GAC and in the AddInViews folder (C:\Program Files\Common Files\Microsoft Shared\VSTA\Pipeline).

If the proxy dll is missing from the AddInViews folder, make sure your proxy mirrors the ShapeAppBasicCSharp sample's build events.  You'll need to copy the InstalInGac.bat and InstallForVB.bat files and set up the build events like this:

call "$(ProjectDir)InstallInGac.bat" "$(TargetPath)"


call "$(ProjectDir)InstallForVB.bat" "$(TargetPath)"

 

 

 

The InstallForVB.bat copies the proxy dll to the pipeline folder and rebuilds the pipeline.  I'm not sure what that has to do with VB but this is necessary for C# as well. 

**Look in the output window during a build to see if these files have run successfully

 

Make sure your add-ins are setup so that there is one folder which contains a folder for each add-in, each add-in folder contains the add-in dll, and the add-in dll name matches the containing folder's name.  To have your add-ins organize

their dll's like this automatically, use the InstallAddIn.js file and post build event (change the host name) from the ShapeApp sample add-ins.

**Changing the add-in name after creating it causes the parent folder name not to match the assembly.

 

If the above suggestions do not work here is a more exhaustive list from our forums:

1)  Run the AddInStore update and re-build (shouldn't have to do both but better safe than sorry).  You can do this programmatically by adding the lines below prior to the AddInStore.FindAddIn's line you sited above, make sure you update

 the paths to the pipeline if needed. 

AddInStore.Update("C:\\Program Files\\Common Files\\Microsoft Shared\\VSTA\\Pipeline");

AddInStore.Rebuild("C:\\Program Files\\Common Files\\Microsoft Shared\\VSTA\\Pipeline");

Still getting the error?

2)  Use the AddInUtil to rebuild both the pipeline and the add-in root.  Here are the commands from the VS Command Prompt to do this for ShapeApp (ignore the warning):

C:\WINDOWS\Microsoft.NET\Framework\v3.5>addinutil -PipelineRoot:"C:\Program Files\Common Files\Microsoft Shared\VSTA\Pipeline" -Rebuild

Warning: Add-in Adapter Microsoft.VisualStudio.Tools.Applications.AddInAdapter,

Microsoft.VisualStudio.Tools.Applications.AddInAdapter.v9.0, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a defines a constructor that doesn't take one parameter.  This constructor can't be used in the add-in model.

C:\WINDOWS\Microsoft.NET\Framework\v3.5>addinutil -AddInRoot:"C:\Documents and Settings\Melody\My Documents\ShapeAppCSharp\AppAddins" -Rebuild

Finished updating cache

Still getting the error?

3)  Review or re-create the project template the add-in was based off of.  Make sure everything is correct, including the add-in's dll is in the correct location, the add-in start up class matches StartUpClass variable of the

VstaRunTimeIntegration class, the add-in builds, and the add-in is looking at the most current version of the proxy.

Still getting the error?

4)  If you are trying to write an add-in in VB, try doing it in CSharp 1st (make sure the VB add-in's dll is removed).  This may work.

 

 

 

 


Posted Jul 08 2009, 04:57 PM by BillL
Filed under: , , ,
Copyright Summit Software Company, 2008. All rights reserved.