2

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.

2
  • What unit testing framework are you using? NUnit? MSTest? Commented Jan 12, 2012 at 20:51
  • It's NUnit. I mentioned ReSharper because at first I was getting strange errors regarding multiple config files when I tried to run NUnit. Figuring it was a separate issue, I suspended it then tried to run them. That's when I ran into the compiler error described above. Commented Jan 12, 2012 at 20:54

1 Answer 1

1

Turns out the issue was related to having multiple DatabaseFactoryConfiguration elements in the app.config file.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.