Justin
Justin

Reputation: 472

Why would application settings not work in an Outlook Add-in or other environment

The Microsoft documentation for application settings states that:

You cannot use application settings in an unmanaged application that hosts the .NET Framework. Settings will not work in such environments as Visual Studio add-ins, C++ for Microsoft Office, control hosting in Internet Explorer, or Microsoft Outlook add-ins and projects.

I created a string in application settings and accessed it from the code, in a Microsoft Outlook Add-in. It seemed to work fine.

In what situations would it not work?

Upvotes: 0

Views: 1169

Answers (1)

Roman Gruber
Roman Gruber

Reputation: 1391

The application settings rely on the presence of a ".config" file to read from. Precisely this would be the ".exe.config" for exe hosts or "web.config" for IIS apps. Outlook, IExplore etc... don't come with your config file. Have you tried changing the value? Settings created with VS have hardcoded defaults and you might be tricked into thinking that it works...

EDIT: The original post stands, because that is how the basic .NET mechanism for configuration files works. However, a host application that runs the .NET Framework has to create an "Application Domain" for it (see http://msdn.microsoft.com/en-us/library/system.appdomain(v=vs.110).aspx ) As part of the creation information for that AppDomain object, the host can specify the path to a configuration file to use (See http://msdn.microsoft.com/en-us/library/system.appdomainsetup.configurationfile(v=vs.110).aspx ). The OS-loader (for EXEs) creates an AppDomain with the ".config" added to the EXE's path as a config file. It seems that (at least some versions of Outlook/.NET) will use the plugin DLL's path with the ".config" addon. This is hard to replicate for me right now but plausible. I remember with an Outlook 2007/.NET 2 addin, it didn't work.

Upvotes: 2

Related Questions