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:

http://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