v00d00
v00d00

Reputation: 3265

VSTO Outlook 2013 third party dll not being found

I am trying to add third party lib to my Outlook 2013 adding written in C#. It consists from 2 components: .Net wrapper and C++ dll itself.

I have referenced .net wrapper in the adding project and added C++ lib as a copy on build resource.

Apparently, Office runtime puts every .Net lib referenced by a plugin in a separate folder excluding C++ lib as it not referenced. And plugin fails to locate C++ lib because it should be in a same folder with the executing dll.

Sample plugin’s dll location :

C:\Users\UserName\AppData\Local\assembly\dl3\TMGBBYEC.3JC\QE21JQR6.YRW\4a3206fe\4acfc661_ccc6cf01\SomeLibName.dll

Any ideas how to fix this?

Upvotes: 1

Views: 260

Answers (1)

Dmitry Streblechenko
Dmitry Streblechenko

Reputation: 66276

Try something like the following to figure out the dll location.

string codebase = Assembly.GetExecutingAssembly().CodeBase;
var vUri = new UriBuilder(codebase);
string vPath = Uri.UnescapeDataString(vUri.Path + vUri.Fragment);
string directory = Path.GetDirectoryName(vPath);
if (!string.IsNullOrEmpty(vUri.Host)) directory = @"\\" + vUri.Host + directory;

Upvotes: 1

Related Questions