SeeMoreGain
SeeMoreGain

Reputation: 1273

Referencing (config file) assembly location while debugging VSTO addin

Due to problem with referencing application config in excel addins (Excel Add-In not loading app.config with service reference config information) I have referenced the assembly location for the config file.

The problem I am now encountering is that each time I launch a debug instance, the assembly is put in a different path (GUID folders under local AppData directory). So I cannot put a copy of the config file in there.

Any suggestions to get around this?

Upvotes: 1

Views: 1349

Answers (1)

SeeMoreGain
SeeMoreGain

Reputation: 1273

Best solution turned out to be discard above solution and use solution from post: Change default app.config at runtime

Because while the original link would then allow you to access the config file, you would have to manually extract the information to bind the webservice.

However originally I did persist with the original and found: To enable the solution in original link to work I had to change the way of accessing directory (which I have now submitted this change to the original linked solution):

AppDomain.CurrentDomain.BaseDirectory

rather than

new FileInfo(Assembly.GetCallingAssembly().Location).DirectoryName

AppDomain.CurrentDomain.BaseDirectory would reference a stable location while debugging (the source directory where the original app.config is located), and the correct install directory for the installed version of the Addin (the addin directory rather than Microsoft Excel directory).

Upvotes: 2

Related Questions