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:
In this case, VSTO will setup the security policy to trust C:My_DocsUserVS_ProjsProjectProject_binProject.dll and when you run the solution it will run the document C:My_DocsUserVS_ProjsProjectProject.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:
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_DocsUserDesktopProject_binProject.dll and when you run the solution it will run the document C:My_DocsUserDesktopProject.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_DocsUserVS_ProjsProject*) 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:
(Of course your code needs to be trusted to display this info...)