I write extensions for a 3rd party application. The application calls my class libraries. I am unsuccessful in getting my assemblies to read from their app.config data when called from another program. Below reproduces the problem with a unit test.
App.config in ConsoleApplication.exe
<appSettings>
<add key="testKey" value="testvalue" />
</appSettings>
static void Main(string[] args)
{
TestClass c = new TestClass();
c.Run();
}
//TestClass.Run()
public void Run()
{
var readAppConfig = ConfigurationManager.AppSettings[0];
MessageBox.Show("App config: " + readAppConfig);
}
Unit test code, MSTEST
[TestMethod]
public void TestAppConfig()
{
TestClass c = new TestClass();
c.Run();//fails here
}
Main() works, TestAppConfig() fails with ArgumentOutOfRangeException
Index was out of range. Must be non-negative and less than the size of
the collection.
Do App.config stop working when called from external assemblies?
the app settings must be in the highest level component (in this case, your MSTEST app.config needs to hold the settings.