Julie wrote to me with a problem about where VSTO creates its DLLs and how they get trusted. Hopefully this will help ;-)
The other day I blogged about how referenced assemblies are copied around, but there's another piece to the puzzle. If you use the New Project wizard to create a VSTO project and elect to create a new document, the wizard places the document in the same folder as the project so you end up with this kind of hierarchy:
// Root project folder
// VS Project files
// The document
// VS output folder
// VS build folder
// VSTO output folder
In this case, VSTO will setup the security policy to trust C:\My_Docs\User\VS_Projs\Project\Project_bin\Project.dll and when you run the solution it will run the document C:\My_Docs\User\VS_Projs\Project\Project.doc which will try and load the assembly through the relative path .\Project_bin.
If you choose to use an existing document, something a bit different happens. VSTO still creates the standard VS project hierarchy, but the Project_bin is created relative to the original document's location. You end up with something like this:
// Note: no document!
// Document folder
In this case, VSTO builds the DLL into the project folder, but then copies it (along with any referenced assemblies) to the document's location as a post-build step. It will also setup the security policy to trust C:\My_Docs\User\Desktop\Project_bin\Project.dll and when you run the solution it will run the document C:\My_Docs\User\Desktop\Project.doc which will try and load the assembly through the relative path .\Project_bin. If you try and set policy to trust the VS project location (C:\My_Docs\User\VS_Projs\Project\*) it won't have any effect since the document / assembly is not loaded from there.
If you want to know where your assembly comes from, it's pretty easy using the CodeBase property of the Assembly object:
' Display the location of the DLL
(Of course your code needs to be trusted to display this info...)