Share via


Troubleshooting common VSTO issues – Part 1

This blog post talks about the common issues related to the VSTO customization failure errors and their possible solutions. Both document as well as application level customizations will be covered here. For the sake of clarity, this blog post is divided into two parts – In first part we will include the VSTO 2.0 common issues and in the second part we will talk about common customization failure issues with VSTO 3.0 and VSTO 4.0.

To see the VSTO related errors for application level projects, use the VSTO_SUPPRESSDISPLAYALERTS  environment variable. Customization failure errors are only shown if the VSTO_SUPPRESSDISPLAYALERTS environment variable is set to 0.

 

Common Error 1:

Customization fails to load with the security exception with the message "The customization does not have the required permissions to execute."

 

The call stack is given below:

System.Security.SecurityException: The customization does not have the required permissions to execute.
at
Microsoft.VisualStudio.Tools.Applications.Runtime.AppDomainManagerInternal.HandleOnlineOffline(Exception e, String basePath, String filePath)
at
Microsoft.VisualStudio.Tools.Applications.Runtime.AppDomainManagerInternal.CreateCustomizationDomainInternal(Uri uriFullDocumentDirectory, Uri uriFullDocFilePath, String documentName, IHostServiceProvider hostCallback, IAddinSecurityManager secman, AppManifest& applicationManifest, Boolean& manifestDirty, IAppInfo& appInfo)
at
Microsoft.VisualStudio.Tools.Applications.Runtime.AppDomainManagerInternal.CreateCustomizationDomain(String applicationDomainPath, String documentName, IHostServiceProvider hostCallback, IExecuteCustomization& executor)
at
Microsoft.VisualStudio.Tools.Applications.Runtime.AppDomainManager.CreateCustomizationDomain(String applicationDomainPath, String documentName, IHostServiceProvider hostCallback, IExecuteCustomization& executor)

Solution/Troubleshooting steps:

To deploy and run a VSTO add-in created using VSTO 2005/VSTO SE, you must grant full trust to the assemblies in the security policy of each end user or computer. Please ensure that the add-in assembly and all the dependent assemblies are given full trust. To know more about How to grant permissions to folders and assemblies, go through the following article:

https://msdn.microsoft.com/en-us/library/zdc263t0(v=vs.80).aspx.

 

Common Error 2:

Customization fails to load and the following dialog box is displayed:

Please note that call stack in the above error dialog box is empty.

Solution/Troubleshooting steps:

There could be multiple reasons for this error. To fix it, try the following:

1) Check that the user has access to the assembly location and that the named assembly exists.

2) Check if the appropriate VSTO Runtime is installed on the machine.

3) Check if CAS permissions are correctly assigned to the assemblies, if the project uses any other third party assemblies or any other dlls, these also need to be given full trust.

4) Disable the other add-ins and then retry.

5) Check if a simple add-in works on the problem machine.

6) Check if VBA (for the Office application for which you are developing customization) is installed on the machine. Document level customizations will not work if VBA is not installed.

 

In case of document level customization, open the document in Application manifest editor and check the assembly location. Ensure that the assembly path exists on the machine and is accessible to the user. Assembly location should be given full trust.

In some of the scenarios, everything mentioned above was taken care of, but still the customization was not loaded and the call stack was empty. In such scenarios, there is a possibility that the Runtime storage control (RSC) is corrupt or it has been deleted accidently from the document. Following VBA code can be used to find if VSTO Runtime storage control is present in the document:

Sub FindVSTORuntimeStorageControl()
    Dim intCtr As Integer
    For intCtr = 1 To ActiveDocument.Shapes.Count
        If ActiveDocument.Shapes(intCtr).Type = msoOLEControlObject Then
            If InStr(1, ActiveDocument.Shapes(intCtr).OLEFormat.ProgID, "VSTO.RuntimeStorage") > 0 Then
                  MsgBox "Runtime Storatge Control Found"
           End If
        End If
    Next
End Sub

If it is not there, remove and then re-attach the customization from the document using the Application manifest editor. If the VSTO runtime storage control is present on the document, first delete the “_AssemblyName” and “_AssemblyLocation” properties of the customized document and then delete the runtime storage control using the following VBA code:

Sub DeleteVSTORuntimeStorageControl()
    Dim intCtr As Integer
    For intCtr = 1 To ActiveDocument.Shapes.Count
         If ActiveDocument.Shapes(intCtr).Type = msoOLEControlObject Then
             If InStr(1, ActiveDocument.Shapes(intCtr).OLEFormat.ProgID, "VSTO.RuntimeStorage") > 0 Then
                     ActiveDocument.Shapes(intCtr).Delete
                     ActiveDocument.Save
             End If

         End If
    Next
End Sub

After you have deleted the control, you can re-attach the customization using Application manifest editor.

 

- Sidharth Shah & Ajay Bandooni