VSTO 2008 Throws CannotCreateCustomizationDomainException when Microsoft Word Math Add-in is installed


In one of my recent cases; one of my customer has installed Visual Studio 2008 SP1, then he tried to create a new Word/Excel add-in project and he gets the following exception :-

"Customization could not be loaded because the application domain could not be created"
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)
at System.Activator.CreateInstance(String assemblyName, String typeName)
at System.AppDomain.CreateInstance(String assemblyName, String typeName)
at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String typeName)
at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String typeName)
at Microsoft.VisualStudio.Tools.Office.Runtime.DomainCreator.CreateCustomizationDomainInternal(String documentFullLocation, String documentName, String assemblyLocation, Boolean showUIDuringDeployment, IntPtr hostServiceProvider, IntPtr& executor)

After some research, we realized that this issue only reproduces when you have another Add-in installed that implements IDTExtensibility2 interface. For Example Microsoft Word Math Add-in

You can easily reproduce the issue at your end using the following steps

1) Install Microsoft Math Add-in for Word 2007
2) Installed Visual Studio 2008 SP1.
3) Create a new Word add-in project and hit F5

Finally we came to know that this is related with one of the CLR bugs and the only way to avoid this is shiming  the COM Add-in For e.g.(The Microsoft Math Add-in for Microsoft Office Word 2007) using the COM shim wizard and register the shimmed dll on the problem machine.

For more details on COM Shim wizard please refer to (http://msdn.microsoft.com/en-us/library/bb508939.aspx )

Comments (3)

  1. Gavin Bateup says:

    Hi,

    I have run into this error with some third party add-ins for Outlook preventing our VSTO add-in from running on a customers system.

    Is this specifically a .NET 3.5 SP1 issue?

    Is there a fix coming to solve the error?

    We don’t have access to the third party software to be creating Shims for their add-ins.

    Thanks

  2. denis khodak says:

    We’ve run into this issue with shimed managed addin, shim must configure application base for custom domain it instantiates:

    ICorRuntimeHost* pHost

    pHost->CreateDomainSetup(&pDomainSetup)

    pDomainSetup->put_ApplicationBase(bstrBaseDir)

    pHost->CreateDomainEx(…, pDomainSetup, …)

    Just pHost->GetDefaultDomain(…) or m_Host>CreateDomain(…) do not work.

    Hopefully Microsoft will fix it soon.

Skip to main content