Share via


Troubleshooting common VSTO issues – Part 2

In this blog post we will talk about some common errors related to VSTO 3.0 and 4.0. For VSTO 2.0 related issues you can check out the blog post Troubleshooting common vsto issues part 1.

Common Error 1:

Customization fails to load while opening a customized document targeting VSTO 3.0/4.0 from a network location with the following exception: 

“CannotCreateCustomizationDomainException: Customization does not have the permissions required to create an application domain. ---> System.Security.SecurityException: Customized functionality in this program will not work because the location of <document> is not in the Office Trusted Locations list, or all trusted locations are disabled.”

The call stack is:

Microsoft.VisualStudio.Tools.Applications.Runtime.CannotCreateCustomizationDomainException: Customization does not have the permissions required to create an application domain. ---> System.Security.SecurityException: Customized functionality in this program will not work because the location of <document> is not in the Office Trusted Locations list, or all trusted locations are disabled. Contact your administrator for further assistance.

at Microsoft.VisualStudio.Tools.Office.Runtime.RuntimeUtilities.VerifyDocumentIsTrusted(String documentFullLocation, String documentName)

at Microsoft.VisualStudio.Tools.Office.Runtime.DomainCreator.CreateCustomizationDomainInternal(String documentFullLocation, String documentName, String assemblyLocation, Boolean showUIDuringDeployment, IntPtr hostServiceProvider, IntPtr& executor)

Solution:

VSTO 3.0 onwards, if you are opening a document level customization from a network share, you need to add that network share to Office Trusted Locations list.

To know how to add a network location to trusted location list, visit:

https://office.microsoft.com/en-us/word-help/create-remove-or-change-a-trusted-location-for-your-files-HA010031999.aspx

 

Common Error 2:

You get the following exception while opening a VSTO 4.0 customization configured to run in VSTOLocal mode against UNC paths:

“CannotCreateCustomizationDomainException: Customization does not have the permissions required to create an application domain. ---> System.Security.SecurityException: Customized functionality in this application will not work because the administrator has listed file:///<path>.vsto as untrusted.”

And the call stack is:

Microsoft.VisualStudio.Tools.Applications.Runtime.CannotCreateCustomizationDomainException: Customization does not have the permissions required to create an application domain. ---> System.Security.SecurityException: Customized functionality in this application will not work because the administrator has listed file:///<path>.vsto as untrusted. Contact your administrator for further assistance.

at Microsoft.VisualStudio.Tools.Office.Runtime.RuntimeUtilities.VerifySolutionUri(Uri uri)

at Microsoft.VisualStudio.Tools.Office.Runtime.DomainCreator.CreateCustomizationDomainInternal(String solutionLocation, String manifestName, String documentName, Boolean showUIDuringDeployment, IntPtr hostServiceProvider, IntPtr& executor)

Solution:

VSTO 4.0 projects configured to run in VSTOLocal mode against UNC paths do not honour the “EnableVSTOLocalUNC” registry key on 64-bit systems. The VSTO Runtime attempts to read the key from the 64-bit VSTOR registry hive instead of the 32-bit VSTOR registry hive.

To fix this issue, create an EnableVSTOLocalUNC key in the 64-bit hive:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Vsto
Runtime Setup\v4]

"EnableVSTOLocalUNC"=dword:00000001

 For more information see KB 2022442.

 

Common Error 3:

VSTO 3.0/4.0 document level customization fails to install with the following exception:

“System.Security.SecurityException: Customized functionality in this application will not work because the certificate used to sign the deployment manifest for <name of the document> or its location is not trusted.”

The call stack is:

System.Security.SecurityException: Customized functionality in this application will not work because the certificate used to sign the deployment manifest for <name of the document> or its location is not trusted. Contact your administrator for further assistance.

at Microsoft.VisualStudio.Tools.Applications.Deployment.ClickOnceAddInTrustEvaluator.VerifyTrustPromptKeyInternal(ClickOnceTrustPromptKeyValue promptKeyValue, DeploymentSignatureInformation signatureInformation, String productName)

at Microsoft.VisualStudio.Tools.Applications.Deployment.ClickOnceAddInTrustEvaluator.VerifyTrustUsingPromptKey(Uri manifest, DeploymentSignatureInformation signatureInformation, String productName)

at Microsoft.VisualStudio.Tools.Applications.Deployment.ClickOnceAddInDeploymentManager.VerifySecurity(ActivationContext context, Uri manifest, AddInInstallationStatus installState)

at Microsoft.VisualStudio.Tools.Applications.Deployment.ClickOnceAddInDeploymentManager.InstallAddIn()

Solution:

Ensure that the ClickOnce trust prompt is enabled for the zone from which you are trying to load the customization. Navigate to the below registry key and ensure that the PromptingLevel is set to Enabled for the zone from where you are trying to load the customization.

On 32 bit machines:

HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\.NETFramework\Security\TrustManager\PromptingLevel

On 64 bit machines:

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\MICROSOFT\.NETFramework\Security\TrustManager\PromptingLevel

For more information, visit How to: Configure Inclusion List Security.

If you are installing the customization from a web site, then make sure that the site is added to the trusted sites.

 

Common Error 4:

You get the following exception while installing the VSTO 3.0/4.0 solution:

“System.Deployment.Application.DeploymentDownloadException: Downloading file:///<path of vsto file> did not succeed.”

Call stack is similar to:

System.Deployment.Application.DeploymentDownloadException: Downloading file:///<path of vsto file> did not succeed. ---> System.Net.WebException: Could not find file '<path of vsto file>'. ---> System.Net.WebException: Could not find file '<path of vsto file>'. ---> System.IO.FileNotFoundException: Could not find file '<path of vsto file>'. File name: '<path of vsto file>'.

at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)

at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)

at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync)

at System.Net.FileWebStream..ctor(FileWebRequest request, String path, FileMode mode, FileAccess access, FileShare sharing, Int32 length, Boolean async)

at System.Net.FileWebResponse..ctor(FileWebRequest request, Uri uri, FileAccess access, Boolean asyncHint)

--- End of inner exception stack trace --

at System.Net.FileWebResponse..ctor(FileWebRequest request, Uri uri, FileAccess access, Boolean asyncHint)

at System.Net.FileWebRequest.GetResponseCallback(Object state)

--- End of inner exception stack trace ---

at System.Net.FileWebRequest.EndGetResponse(IAsyncResult asyncResult)

at System.Net.FileWebRequest.GetResponse()

at System.Deployment.Application.SystemNetDownloader.DownloadSingleFile(DownloadQueueItem next)

--- End of inner exception stack trace ---

at Microsoft.VisualStudio.Tools.Applications.Deployment.ClickOnceAddInDeploymentManager.GetManifests(TimeSpan timeout)

at Microsoft.VisualStudio.Tools.Applications.Deployment.ClickOnceAddInDeploymentManager.InstallAddIn()

Solution:

This issue is generally seen when the VSTO solution is trying to get certificate information (publisher name and other data) from Domain Controller and it times out. To resolve the issue, please install this hotfix :- KB 981574.

 

Common Error 5:

You get following exception when you try to use VSTO 3.0/4.0 customization:

“CannotCreateCustomizationDomainException: Customization could not be loaded because the application domain could not be created. ---> System.IO.FileLoadException: Loading this assembly would produce a different grant set from other instances. (Exception from HRESULT: 0x80131401)”

The call stack is:

Microsoft.VisualStudio.Tools.Applications.Runtime.CannotCreateCustomizationDomainException: Customization could not be loaded because the application domain could not be created. ---> System.IO.FileLoadException: Loading this assembly would produce a different grant set from other instances. (Exception from HRESULT: 0x80131401)

at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)

at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)

at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)

at System.Activator.CreateInstance(Type type, Boolean nonPublic)

at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)

at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)

at System.Activator.CreateInstance(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo, StackCrawlMark& stackMark)

Solution/Troubleshooting steps:

This issue is a bug with .NET CLR. This issue has been fixed in KB 981574. To resolve the issue, please install this hotfix :- KB 981574

 

- Sidharth Shah & Ajay Bandooni

Comments

  • Anonymous
    June 02, 2013
    I face the same issue as described under "Common Error 4:" - the same exception, the same call-stack. The solution described here is to install hotfix KB 981574. However, this hotfix is mentioned to be relevant only with .NET framework 3.5 or .NET Framework 2.0, but there is only .NET Framework 4.0 installed on my PC. Is this hotfix application also for .NET Framework 4.0 or is there another hotfix or does it mean that my issue is a different one than described here? Remark: My application is document level add-in with template targeted on .NET Framework 4.0.

  • Anonymous
    July 23, 2015
    Hi Ajay, I am trying to download the Excel customization from a intranet website and I have added the website as a trusted location as excel and also set the Prompting Level for the Intranet zone as mentioned in the inclusion list site. But I am still getting the below error while trying to download and open the template (saving the template works) from the intranet website. Can you please provide any inputs on this. I been looking for a solution everywhere. Microsoft.VisualStudio.Tools.Applications.Runtime.CannotCreateCustomizationDomainException: This document contains custom code that cannot be loaded because the location is not in your trusted locations list: Thanks, Ram

  • Anonymous
    February 06, 2017
    So if I want to develop a VSTO AddIn for my work place but I'm getting 'Common Error 3'. Does everyone who wants to use my AddIn also have to have the ClickOnce trust prompt enabled in their registry?I've downloaded the VBA code cleaner AddIn from the internet, for instance, and not had such a problem so why should developing my own AddIn in my work's domain give me this problem?

    • Anonymous
      March 31, 2017
      "Common Error 3" is applicable for document level addins/customizations.
  • Anonymous
    December 12, 2017
    Fixed by problem by adding the code signing cert to Trusted Publishers cert store