Reputation: 460
I've created a word add-in, which uses one of my DLL's. The application works fine when I'm running it in Visual Studio (both debug or release mode), however when I try starting Word on it's own (and the add-in is still present) and then proceed to trigger a method which loads the DLL, I get a DLL error as shown in the picture below. I'm quiet certain that the problem is not related to x86/x64 compatibility issues as I've set the platform target to x86 for all projects. (The version of Word used for testing is also 32-bit). Any ideas as to what the problem might be will be greatly appreciated, thanks in advance!
Upvotes: 0
Views: 1350
Reputation: 460
So after a day of Googling, I found my solution. It turns out that Word (and Office programs in general) moves your dll's into separate temporary directories - found in:
$User\AppData\Local\assembly\dl3
My dll depended on other resources in the same directory, but because it was being moved separately into this temporary directory then the dll could not be loaded. To get around this, I loaded the dll manually from the directory that it was installed in using:
System.Reflection.Assembly.LoadFile(string path)
You can get the directory that it was installed in with these lines of code:
System.Reflection.Assembly assemblyInfo = System.Reflection.Assembly.GetExecutingAssembly();
//Location is where the assembly is run from
string assemblyLocation = assemblyInfo.Location;
//CodeBase is the location of the ClickOnce deployment files
Uri uriCodeBase = new Uri(assemblyInfo.CodeBase);
string ClickOnceLocation = Path.GetDirectoryName(uriCodeBase.LocalPath.ToString());
Upvotes: 4