Reputation: 717
I have a 3 project solution that comprises of my DAL, an assembly, and my unit test project. I am using ReSharper.
The following field, in my DAL, returns NULL for the object SectionHandler:
public static DatabaseFactorySectionHandler SectionHandler =
(DatabaseFactorySectionHandler) ConfigurationManager.GetSection("DatabaseFactoryConfiguration");
This is a line from a Factory class. Another class that inherits from it attempts to initialize the field from its constructor.
I remembered I needed to add my App.config file to my Unit Test project (it was pointing to Machine.config). However, it hasn't fixed the problem. What I get instead when attempting to run my test is:
> failed: Configuration system failed to initialize System.Configuration.ConfigurationErrorsException: Configuration > system failed to initialize ---> > System.Configuration.ConfigurationErrorsException: Unrecognized > configuration section section. > (C:\projects\MyAssembly.Tests\bin\Debug\MyAssembly.Tests.dll.temp.config > line 3)
What I don't understand is the naming of the config file. In my directory I can see App.config has been renamed correctly (MyAssembly.Tests.dll.config), but there is no sign of temp.config.
Here's my app.config (this is what is currently in my Test project, there are no other App.configs in the solution)
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="DatabaseFactoryConfiguration" type="MyClass.DatabaseFactorySectionHandler, MyClass.DBConnector, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</configSections>
<connectionStrings>
<clear/>
<add name="Connector1" providerName="MyProvider" connectionString="myConnString" />
<add name="DB2Connector" providerName="IBM.Data.DB2" connectionString="myConnString2" />
</connectionStrings>
<DatabaseFactoryConfiguration Name="MyClassHere" ConnectionStringName="Connector1" />
<DatabaseFactoryConfiguration Name="MyOtherClassHere" ConnectionStringName="DB2Connector" />
</configuration>
Why can't I get the unit test project to recognize my config file? Thanks.
Upvotes: 2
Views: 2296
Reputation: 717
Turns out the issue was related to having multiple DatabaseFactoryConfiguration elements in the app.config file.
Upvotes: 1