Error creating documents (Excel/Word) in my Office Addin when Autodesk Vault Office Addin is loaded and connected to Vault
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello there,
I'm currently working on an Office Addin (VSTO technology) and have a problem.
Office is 32 bit
Vault version is 2020.
The problem is only present when the user is logged in to Vault using Autodesk's Vault addin for Office (Word and Excel). When user isn't logged in, everything works as expected.
Regarding Excel, I get and error when trying to add a new Excel workbook to Excel's WorkBooks Collection and in Word the problem occurs when I try to save a newly created document to disk using document.SaveAs/document.SaveAs2 method
Code in Excel Addin :
private void button1_Click(object sender, EventArgs e)
{
try
{
//AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
//string currPath = System.Environment.GetEnvironmentVariable("PATH");
//currPath = @"C:\Program Files (x86)\Autodesk\DM Apps\Office Addin 2020\;" + currPath;
//System.Environment.SetEnvironmentVariable("PATH", currPath);
Microsoft.Office.Interop.Excel.Workbook newDoc = null;
newDoc = ExcelAddIn1.Globals.ThisAddIn.Application.Workbooks.Add();
newDoc.SaveAs(@"c:\temp\temp.xlsx");
}
catch (Exception ex) { }
finally
{
//AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomain_AssemblyResolve;
}
}
private System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
string[] asmName;
string asmPath;
asmName = args.Name.Split(",".ToCharArray());
if (Environment.Is64BitProcess) { asmPath = @"D:\SourceCode\_AzureDevOps\NTI.Tools.Acw\_Build\AddCardWizard" + @"\Vault 2020 (x64)\x64\" + asmName[0] + ".dll"; }
else { asmPath = @"C:\Program Files (x86)\Autodesk\DM Apps\Office Addin 2020\" + asmName[0] + ".dll"; }
if (System.IO.File.Exists(asmPath))
{
System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFile(asmPath);
return assembly;
}
return null;
}
When I run the code above, I get the following error:
("Could not load file or assembly 'Connectivity.Common.Windows, Version=1.0.6996.38200, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.")
As the code shows, I have tried different things to make this work :
1. tried adding the path where the Vault Office Vault files are located to environment variable PATH
2. tried using assembly resolve to point to the location of the Vault Office files.
Modifing environment PATH, does not make any difference. When adding a AssemblyResolve handler, the event gets fires and I returns the assemblies found in 'C:\Program Files (x86)\Autodesk\DM Apps\Office Addin 2020' (Vault Office addin folder installed by Vault Client). When using AssemblyResolve, I get the following nasty error :
and Excel crashes.
NOTE : All of this above only happens when Vault Addin is loaded and users is connected to Vault. I found a post from 2013 https://forums.autodesk.com/t5/vault-customization/filenotfoundexception-in-office-s-saveas-methods/... with the same problem (my Word problem is as described in the post)
I'm able to reproduce the problem consistently using a very simple example as shown above. I'm very sure this must be something in "C:\Program Files (x86)\Autodesk\DM Apps\Office Addin 2020\VaultClient.dll" (Vault Office addin) which is causing the problem.
I'm aware that Vault 2020 sdk is only present in 64bit, but the problem shown in the example, does not use any Vault assemblies/references. But problem still occurs
Someone who can point me in the right direction ?
Thank you