Proxy Assembly Registration- Unique Name Required

VSTA v 2.0 add-ins use two mechanisms to associate add-ins with proxy assemblies.  These include the Global Assembly Cache (GAC) and the VSTA pipeline.  Each has separate considerations to take into account when naming your proxy assembly.

 

The Global Assembly Cache (GAC) and Add-in Projects 
The proxy assembly should be registered in the GAC so that add-in projects can resolve the reference without requiring a local copy or absolute path.  It is possible to get around this by modifying the project templates to use a hint path, but ProjectGen will complain if the proxy assembly in not registered here.  Considerations, including naming schemes, for how add-in projects resolve the reference to the proxy assembly registered in the GAC have been covered in a previous blog, Proxy Versioning Options for Project Templates

The SDK samples register the proxy assembly in the GAC using a post build event and the file InstallInGAC.bat.

 

The VSTA pipeline and Visual Basic Add-in Assemblies
When Visual Basic add-ins are loaded through the VSTA pipeline, the proxy assembly must be registered with the pipeline.  This means that the proxy assembly should be copied to %Common Program Files%\Microsoft Shared\VSTA\Pipeline\AddInViews (see the section on "Additional Requirments for Visual Basic Add-ins" in the MSDN documentation for Creating Proxies).  Unlike the GAC, proxies with non-unique names cannot co-exist here; therefore, proxy assemblies must use unique names or they will be overwritten


If the proxy assembly is not present here, then Visual Basic add-ins will not load.  Instead they will throw a file not found a FileNotFoundException when activate is called (see code and exception below).  In the case where the proxy assembly is overwritten, the results will vary depending on the compatibility of the proxy assemblies.  If the assemblies are completely incompatible then the addInToken.Count will be zero.


The SDK samples register the proxy with the VSTA pipeline by using a post build event and the file InstallForVB.bat which copies the proxy assembly to %Common Program Files%\Microsoft Shared\VSTA\Pipeline\AddInViews and runs AddInUtil –PipelineRoot:”%Pipeline location%” -Rebuild

Note this is not a consideration for C# add-ins. 

 


FileNotFoundException will occur here if the proxy is not in C:\Program Files\Common Files\Microsoft Shared\VSTA\Pipeline\AddInViews when attempting to load a VB add-in
IEntryPoint addIn = addInToken[0].Activate<IEntryPoint> _
                   
 (AddInSecurityLevel.FullTrust);


Exception if proxy assembly is not in …VSTA\Pipeline\AddInViews:
System.IO.FileNotFoundException was caught
  Message="Could not load file or assembly 'file:///C:\\Program Files\\Common Files\\Microsoft Shared\\VSTA\\Pipeline\\AddInViews\\ShapeAppCSharpProxy.dll' or one of its dependencies. The system cannot find the file specified."

       at System.AddIn.Hosting.AddInToken.Activate[T](AddInSecurityLevel trustLevel)
       at Microsoft.VisualStudio.Tools.Applications.Samples.ShapeApp.VstaRunTimeIntegration.LoadAddIn(String addInPath, String startUpClass) in C:\ShapeAppSamples\VSTA v 2 RTM\ShapeAppBasicCSharp\integration\basic\VstaRunTimeIntegration.cs:line 161



addInToken.Count will be zero if the proxy was overwritten by an incompatible proxy:

 

Collection<AddInToken> addInToken = AddInStore.FindAddIn(typeof(IEntryPoint), AddInStoreExtensions.DefaultPipelinePath, addInPath, startUpClass);

Related blogs:
Proxy Versioning Options for Project Templates
VSTA v 2 Proxy Names- Unique Names for Proxy Versions
Creating Proxies- Installing the Proxy Assembly with the Host Application

VSTA Pipeline location:
C:\Program Files\Common Files\Microsoft Shared\VSTA\Pipeline

Proxy assemblies are stored in:
C:\Program Files\Common Files\Microsoft Shared\VSTA\Pipeline\AddInViews


Posted Jan 26 2009, 03:53 PM by Melody
Filed under: , , ,
Copyright Summit Software Company, 2008. All rights reserved.