Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unrecognized configuration section applicationSettings in NHibernate

I'm using fluent NHibernate.

I have an app.config file with few specific keys (applicationSettings and userSettings).

It seems that the nhibernate doesn't like these keys. As long as these keys exist in the file, the Fluently.Configure() fails and an exception with the message Unrecognized configuration section applicationSettings is thrown.

What can I do?

Here is the config file:

<?xml version="1.0"?>
<configuration>
  <connectionStrings>
    <add name="MyDB" connectionString="Data Source=|DataDirectory|\MyDB.sdf" providerName="Microsoft.SqlServerCe.Client.3.5" />
</connectionStrings>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
  <applicationSettings>
        <MyApp.Properties.Settings>
            <setting name="ServerIp" serializeAs="String">
                <value>127.0.0.1</value>
            </setting>
            <setting name="ServerPort" serializeAs="String">
                <value>5678</value>
            </setting>
            <setting name="UseSSL" serializeAs="String">
                <value>True</value>
            </setting>
            <setting name="WsUrl" serializeAs="String">
                <value/>
            </setting>
        </MyApp.Properties.Settings>
    </applicationSettings>
    <userSettings>
        <MyApp.Properties.Settings>
            <setting name="User" serializeAs="String">
                <value>test</value>
            </setting>
            <setting name="Password" serializeAs="String">
                <value>test</value>
            </setting>
        </MyApp.Properties.Settings>
    </userSettings>
</configuration>

Thank you!

like image 871
Programatic Avatar asked May 03 '12 21:05

Programatic


1 Answers

Your error Message is pretty much on-the-spot and has nothing to do with NHibernate: Configuration needs to know what ConfigSections it will provide, which you did not specify. This should not happen, did VS create the app.config for you?

<?xml version="1.0"?>
<configuration>
  <configSections>
    <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <section name="MyApp.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
    </sectionGroup>
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
      <section name="MyApp.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </sectionGroup>
  </configSections>
  <userSettings>
    <!--...-->
  </userSettings>
  <applicationSettings>
    <!--...-->
  </applicationSettings>
</configuration>

If you want further background on how Configuration works, read this for a start.

like image 87
Sebastian Edelmeier Avatar answered Sep 28 '22 05:09

Sebastian Edelmeier